public void Register(Type @interface, Type service, LifeScope lifeScope = LifeScope.Transient) { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType(service).As(@interface).SetLifeScope(lifeScope); builder.Update(container); }
public void Register <TInterface, TService>(string name, LifeScope lifeScope = LifeScope.Transient) where TService : TInterface { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType <TService>().As <TInterface>().Named(name, typeof(TInterface)).SetLifeScope(lifeScope); builder.Update(container); }
public void Register <TService>(LifeScope lifeScope = LifeScope.Transient) { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType <TService>().AsSelf().SetLifeScope(lifeScope); builder.Update(container); }
public void Register(Type service, string name, LifeScope lifeScope = LifeScope.Transient) { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType(service).Named(name, service).SetLifeScope(lifeScope); builder.Update(container); }
public void Register(Type @interface, Type type, string name, LifeScope lifeScope = LifeScope.Transient) { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType(type).As(@interface).Named(name, @interface).SetLifeScope(lifeScope); builder.Update(container); }
public void Register <TService>(TService instance, Type aliasType, LifeScope lifeScope = LifeScope.Single) where TService : class { var registerBuilder = _builder.RegisterInstance(instance).SetLifeScope(lifeScope); if (aliasType != null) { registerBuilder.As(aliasType); } }
public IDisposable Resolve <TService>(out TService service) where TService : class { if (_isDisposed) { throw new ObjectDisposedException(nameof(Container)); } var transientLifeScope = new LifeScope(); service = _resolver.Resolve <TService>(transientLifeScope); return(transientLifeScope); }
public void RegisterType <TService>(string serviceName = null, LifeScope life = LifeScope.Singleton) { var registrationBuilder = _containerBuilder.RegisterType <TService>(); if (serviceName != null) { registrationBuilder.Named <TService>(serviceName); } switch (life) { case LifeScope.PerDependency: registrationBuilder.InstancePerDependency(); break; case LifeScope.Singleton: registrationBuilder.SingleInstance(); break; } }
public static void Register <TService>(LifeScope lifeScope = LifeScope.Single) { _container.Register <TService>(lifeScope); }
public static void Register(Type serviceType, LifeScope lifeScope = LifeScope.Single) { _container.Register(serviceType, lifeScope); }
public Configuration SetDefault <TInterface, TService>(LifeScope lifeScope = LifeScope.Transient) where TService : TInterface { Container.Current.Register <TInterface, TService>(lifeScope); return(this); }
/// <summary> /// 注册一个Service类型的实现类 /// </summary> /// <typeparam name="TSerivce"></typeparam> /// <typeparam name="TImplementer"></typeparam> /// <param name="serviceName"></param> /// <param name="life"></param> public static void Register <TSerivce, TImplementer>(string serviceName = null, LifeScope life = LifeScope.Singleton) where TSerivce : class where TImplementer : class, TSerivce { Current.Register <TSerivce, TImplementer>(serviceName, life); }
internal static IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> SetLifeScope <TLimit, TActivatorData, TRegistrationStyle>(this IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> registerInfo, LifeScope lifeScope) { if (lifeScope == LifeScope.Single) { registerInfo.SingleInstance(); } return(registerInfo); }
public static IRegistrationBuilder <TLimit, TReflectionActivatorData, TStyle> SetLifeScope <TLimit, TReflectionActivatorData, TStyle>(this IRegistrationBuilder <TLimit, TReflectionActivatorData, TStyle> builder, LifeScope lifeScope) { if (lifeScope == LifeScope.Single) { return(builder.SingleInstance()); } return(builder); }
/// <summary> /// 注册类型 /// </summary> /// <typeparam name="TService"></typeparam> /// <param name="serviceName"></param> /// <param name="life"></param> public static void RegisterType <TService>(string serviceName = null, LifeScope life = LifeScope.Singleton) { Current.RegisterType <TService>(serviceName, life); }
public void RegisterType(Type serviceType, Type implementationType, string serviceName = null, LifeScope life = LifeScope.Singleton) { var registrationBuilder = _containerBuilder.RegisterType(implementationType).As(serviceType); if (serviceName != null) { registrationBuilder.Named(serviceName, serviceType); } switch (life) { case LifeScope.PerDependency: registrationBuilder.InstancePerDependency(); break; case LifeScope.Singleton: registrationBuilder.SingleInstance(); break; } }
public static void RegisterInstance <TService>(TService instance, Type aliasType = null, LifeScope lifeScope = LifeScope.Single) where TService : class { _container.Register(instance, aliasType, lifeScope); }
public Configuration SetDefault <TService, TImplementer>(string serviceName = null, LifeScope life = LifeScope.Singleton) where TService : class where TImplementer : class, TService { ObjectContainer.Register <TService, TImplementer>(serviceName, life); return(this); }
public void Register <TService>(LifeScope lifeScope = LifeScope.Single) { _builder.RegisterType <TService>().SetLifeScope(lifeScope); }
public void Register(Type serviceType, LifeScope lifeScope = LifeScope.Single) { _builder.RegisterType(serviceType).SetLifeScope(lifeScope); }
/// <summary> /// 注册一个Service类型的实现类 /// </summary> /// <param name="serviceType"></param> /// <param name="implementationType"></param> /// <param name="serviceName"></param> /// <param name="life"></param> public static void RegisterType(Type serviceType, Type implementationType, string serviceName = null, LifeScope life = LifeScope.Singleton) { Current.RegisterType(serviceType, implementationType, serviceName, life); }