Пример #1
0
        /// <summary>
        /// Registers single generic Type.  LifeTime options can be used.
        /// </summary>
        public void Register <TImplementation>(LifeTimeStyle lsType)
            where TImplementation : class
        {
            if (!typeof(TImplementation).IsClass || typeof(TImplementation).IsAbstract)
            {
                throw new Exception(string.Format("Single generics needs to be only concrete classes. Name: {0}",
                                                  typeof(TImplementation).FullName));
            }

            Register <TImplementation, TImplementation>(lsType);
        }
Пример #2
0
        /// <summary>
        /// Registers Type with the concrete implementation. LifeTime options can be used.
        /// </summary>
        public void Register <TContract, TImplementation>(LifeTimeStyle lsType)
            where TContract : class
            where TImplementation : class
        {
            if (types.ContainsKey(typeof(TContract)))
            {
                throw new Exception(string.Format("Type {0} already registered.", typeof(TContract).FullName));
            }

            IInstanceLifeTimeFactory lifeTimeFactory = new InstanceLifeTimeFactory();

            types[typeof(TContract)] = lifeTimeFactory.Create(typeof(TImplementation), lsType, null);
        }
Пример #3
0
        protected override void DoRegister <T>(LifeTimeStyle lifeTimeStyle)
        {
            switch (lifeTimeStyle)
            {
            case LifeTimeStyle.Singleton:
                services.AddSingleton <T>();
                break;

            case LifeTimeStyle.Transient:
                services.AddTransient <T>();
                break;

            case LifeTimeStyle.Scoped:
                services.AddScoped <T>();
                break;
            }
        }
Пример #4
0
        protected override void DoRegister(Type type, Type impl, LifeTimeStyle lifeTimeStyle)
        {
            switch (lifeTimeStyle)
            {
            case LifeTimeStyle.Singleton:
                services.AddSingleton(type, impl);
                break;

            case LifeTimeStyle.Transient:
                services.AddTransient(type, impl);
                break;

            case LifeTimeStyle.Scoped:
                services.AddScoped(type, impl);
                break;
            }
        }
        public IInstanceLifeTime Create(Type t, LifeTimeStyle lt, object o)
        {
            switch (lt)
            {
            case LifeTimeStyle.Singleton:
                return(new SingletonLifeTime()
                {
                    ResolvedType = t,
                    InstanceValue = o
                });

            default:
                return(new TransientLifeTime()
                {
                    ResolvedType = t,
                    InstanceValue = null
                });
            }
        }
Пример #6
0
 public void Register <T>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) where T : class
 {
     ObjectContainer.Register <T>(lifeTimeStyle);
 }
Пример #7
0
 public void Register(Type type, Type impl, LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton)
 {
     ObjectContainer.Register(type, impl, lifeTimeStyle);
 }
Пример #8
0
 public void Register <TType, TImpl>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton)
     where TType : class
     where TImpl : class, TType
 {
     ObjectContainer.Register <TType, TImpl>(lifeTimeStyle);
 }
Пример #9
0
 public void Register <T>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) where T : class
 {
     this.DoRegister <T>(lifeTimeStyle);
 }
Пример #10
0
 protected abstract void DoRegister <T>(LifeTimeStyle lifeTimeStyle) where T : class;
Пример #11
0
 public void Register(Type type, Type impl, LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton)
 {
     this.DoRegister(type, impl, lifeTimeStyle);
 }
Пример #12
0
 protected abstract void DoRegister(Type type, Type impl, LifeTimeStyle lifeTimeStyle);
Пример #13
0
 public void Register <TType, TImpl>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton)
     where TType : class
     where TImpl : class, TType
 {
     this.DoRegister <TType, TImpl>(lifeTimeStyle);
 }
Пример #14
0
 protected abstract void DoRegister <TType, TImpl>(LifeTimeStyle lifeTimeStyle)
     where TType : class
     where TImpl : class, TType;