Exemplo n.º 1
0
 /// <summary>
 /// Used to replace a service type.
 /// </summary>
 /// <typeparam name="TType">Type of the service.</typeparam>
 /// <typeparam name="TImpl">Type of the implementation.</typeparam>
 /// <param name="configuration">The configuration.</param>
 /// <param name="lifeStyle">Life style.</param>
 public void ReplaceService <TInter, TImpl>(DependencyLife lifeStyle = DependencyLife.Singleton)
     where TInter : class
     where TImpl : TInter
 {
     ReplaceService(typeof(TInter), () =>
     {
         IocManager.Register <TInter, TImpl>(lifeStyle);
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// 注册类型
        /// </summary>
        /// <param name="type"></param>
        public void Register(Type type, DependencyLife life)
        {
            switch (life)
            {
            case DependencyLife.Singleton:
                IocContainer.Register(
                    Component.For(type)
                    .ImplementedBy(type)
                    .LifestyleSingleton());
                break;

            case DependencyLife.Transient:
                IocContainer.Register(
                    Component.For(type)
                    .ImplementedBy(type)
                    .LifestyleTransient());
                break;
            }
        }
Exemplo n.º 3
0
        public void Register <TInter, TImpl>(DependencyLife life = DependencyLife.Transient) where TInter : class
            where TImpl : TInter
        {
            switch (life)
            {
            case DependencyLife.Transient:

                IocContainer.Register(
                    Component.For <TInter>()
                    .ImplementedBy <TImpl>()
                    .LifestyleTransient()
                    );
                break;

            case DependencyLife.Singleton:
                IocContainer.Register(
                    Component.For <TInter>()
                    .ImplementedBy <TImpl>()
                    .LifestyleSingleton()
                    );
                break;
            }
        }