/// <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); }); }
/// <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; } }
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; } }