public virtual IDependencyManager Register(TypeInfo serviceType, TypeInfo implementationType, string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance, bool overwriteExciting = true) { return(Register(new[] { serviceType }, implementationType, name, lifeCycle, overwriteExciting)); }
public virtual IDependencyManager Register(TypeInfo[] servicesType, TypeInfo implementationType, string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance, bool overwriteExciting = true) { if (implementationType == null) { throw new ArgumentNullException(nameof(implementationType)); } if (servicesType == null) { throw new ArgumentNullException(nameof(servicesType)); } IRegistrationBuilder <object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registration = GetContainerBuidler().RegisterType(implementationType) .PropertiesAutowired(wiringFlags: PropertyWiringOptions.PreserveSetValues) .As(servicesType); if (overwriteExciting == false) { registration = registration.PreserveExistingDefaults(); } if (name != null) { foreach (TypeInfo serviceType in servicesType) { registration = registration.Named(name, serviceType); } } if (lifeCycle == DependencyLifeCycle.Transient) { registration = registration.InstancePerDependency(); } else if (lifeCycle == DependencyLifeCycle.SingleInstance) { registration = registration.SingleInstance(); } else { registration = registration.InstancePerLifetimeScope(); } return(this); }
public virtual IDependencyManager RegisterUsing(Func <IDependencyResolver, object> factory, TypeInfo serviceType, string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance, bool overwriteExciting = true) { return(RegisterUsing(factory, new[] { serviceType }, name, lifeCycle, overwriteExciting)); }
public virtual IDependencyManager RegisterUsing(Func <IDependencyResolver, object> factory, TypeInfo[] servicesType, string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance, bool overwriteExciting = true) { IRegistrationBuilder <object, SimpleActivatorData, SingleRegistrationStyle> registration = GetContainerBuidler().Register((context, parameter) => { AutofacDependencyManager currentAutofacDepdencyManager = new AutofacDependencyManager(); currentAutofacDepdencyManager.UseContainer(context.Resolve <ILifetimeScope>()); return(factory.DynamicInvoke(currentAutofacDepdencyManager)); }).As(servicesType); if (overwriteExciting == false) { registration = registration.PreserveExistingDefaults(); } if (name != null) { foreach (TypeInfo serviceType in servicesType) { registration = registration.Named(name, serviceType); } } if (lifeCycle == DependencyLifeCycle.Transient) { registration = registration.InstancePerDependency(); } else if (lifeCycle == DependencyLifeCycle.SingleInstance) { registration = registration.SingleInstance(); } else { registration = registration.InstancePerLifetimeScope(); } return(this); }
public IDependencyManager RegisterGeneric(TypeInfo[] servicesType, TypeInfo implementationType, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance) { IRegistrationBuilder <object, ReflectionActivatorData, DynamicRegistrationStyle> registration = GetContainerBuidler().RegisterGeneric(implementationType) .PropertiesAutowired(wiringFlags: PropertyWiringOptions.PreserveSetValues) .As(servicesType); if (lifeCycle == DependencyLifeCycle.Transient) { registration = registration.InstancePerDependency(); } else if (lifeCycle == DependencyLifeCycle.SingleInstance) { registration = registration.SingleInstance(); } else { registration = registration.InstancePerLifetimeScope(); } return(this); }
public virtual IDependencyManager RegisterUsing <T>(Func <IDependencyResolver, T> factory, string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance, bool overwriteExciting = true) { return(RegisterUsing((depManager) => factory(depManager), new[] { typeof(T).GetTypeInfo() }, name, lifeCycle, overwriteExciting)); }
public virtual IDependencyManager RegisterAssemblyTypes(Assembly[] assemblies, Predicate <TypeInfo> predicate = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance) { IRegistrationBuilder <object, ReflectionActivatorData, DynamicRegistrationStyle> registration = GetContainerBuidler().RegisterAssemblyTypes(assemblies) .Where(t => predicate == null || predicate(t.GetTypeInfo())) .PropertiesAutowired(wiringFlags: PropertyWiringOptions.PreserveSetValues); if (lifeCycle == DependencyLifeCycle.Transient) { registration = registration.InstancePerDependency(); } else if (lifeCycle == DependencyLifeCycle.SingleInstance) { registration = registration.SingleInstance(); } else { registration = registration.InstancePerLifetimeScope(); } return(this); }
/// <summary> /// Register an unparameterized generic type, e.g. IRepository<>. Concrete types will be made as they are requested, e.g. with IRepository<Customer> /// </summary> public IDependencyManager RegisterGeneric(TypeInfo serviceType, TypeInfo implementationType, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance) { return(RegisterGeneric(new[] { serviceType }, implementationType, lifeCycle)); }
public virtual IDependencyManager Register <TService, TImplementation>(string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance, bool overwriteExciting = true) where TImplementation : class, TService { return(Register(new[] { typeof(TService).GetTypeInfo() }, typeof(TImplementation).GetTypeInfo(), name, lifeCycle, overwriteExciting)); }
public virtual IDependencyManager Register(TypeInfo contractType, TypeInfo serviceType, string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.InstancePerLifetimeScope, bool overwriteExciting = true) { if (serviceType == null) { throw new ArgumentNullException(nameof(serviceType)); } if (contractType == null) { throw new ArgumentNullException(nameof(contractType)); } var registration = GetContainerBuidler().RegisterType(serviceType) .PropertiesAutowired() .As(contractType); if (overwriteExciting == false) { registration = registration.PreserveExistingDefaults(); } if (name != null) { registration = registration.Named(name, contractType); } if (lifeCycle == DependencyLifeCycle.SingleInstance) { registration = registration.SingleInstance(); } else { registration = registration.InstancePerLifetimeScope(); } return(this); }
public IDependencyManager RegisterGeneric(TypeInfo contractType, TypeInfo serviceType, DependencyLifeCycle lifeCycle) { IRegistrationBuilder <object, ReflectionActivatorData, DynamicRegistrationStyle> registration = GetContainerBuidler().RegisterGeneric(serviceType).PropertiesAutowired().As(contractType); if (lifeCycle == DependencyLifeCycle.SingleInstance) { registration = registration.SingleInstance(); } else { registration = registration.InstancePerLifetimeScope(); } return(this); }
public virtual IDependencyManager Register <TContract, TService>(string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.InstancePerLifetimeScope, bool overwriteExciting = true) where TService : class, TContract { return(Register(typeof(TContract).GetTypeInfo(), typeof(TService).GetTypeInfo(), name, lifeCycle, overwriteExciting)); }
public virtual IDependencyManager Register <T>(string name = null, DependencyLifeCycle lifeCycle = DependencyLifeCycle.PerScopeInstance, bool overwriteExciting = true) where T : class { return(Register <T, T>(name, lifeCycle, overwriteExciting)); }