view Implab.ServiceHost/Unity/AbstractRegistration.cs @ 281:e0916ddc9950 v3 tip

code cleanup and refactoring
author cin
date Fri, 01 Jun 2018 21:35:24 +0300
parents 8714471e8d78
children
line wrap: on
line source

using System;
using System.Xml.Serialization;
using Unity.Lifetime;
using Unity.Registration;

namespace Implab.ServiceHost.Unity
{
    /// <summary>
    /// Базовая информаци о регистрации в контейнере: тип, имя и время жизни
    /// </summary>
    public abstract class AbstractRegistration : AbstractContainerItem, IRegistration {

        /// <summary>
        /// An optional name for a registration in the container
        /// </summary>
        [XmlAttribute("name")]
        public string Name {
            get; set;
        }

        [XmlElement("signleton", typeof(SingletonLifetimeElement))]
        [XmlElement("context", typeof(ContextLifetimeElement))]
        [XmlElement("container", typeof(ContainerLifetimeElement))]
        [XmlElement("hierarchy", typeof(HierarchicalLifetimeElement))]
        public LifetimeElement Lifetime {get; set;}

        /// <summary>
        /// A type specification for the service registration, 
        /// </summary>
        [XmlAttribute("type")]
        public string RegistrationType { get; set; }

        public virtual LifetimeManager GetLifetime(ContainerBuilder builder) {
            return Lifetime?.GetLifetime(builder);
        }

        public virtual Type GetRegistrationType(Func<string,Type> resolver) {
            return resolver(RegistrationType);
        }

        public virtual Type GetRegistrationType(ContainerBuilder builder) {
            return builder.ResolveType(RegistrationType);
        }

        

    }
}