public static IIocRegistrator RegisterSingleton <TService, TImplementation>( this IIocRegistrator registrator, bool autoInjectProperty = false) where TImplementation : TService { return(registrator.Register <TService, TImplementation>( autoInjectProperty, DependencyLifeTime.Singleton)); }
public static IIocRegistrator RegisterManyTransient( this IIocRegistrator registrator, Type implementationType, bool autoInjectProperty = false) { return(registrator.RegisterMany( implementationType, autoInjectProperty, DependencyLifeTime.Transient)); }
private void RegisterPubSubComponents(IIocRegistrator reg, ITypeFinder typeFinder) { reg.RegisterType <EventPublisher, IEventPublisher>(LifeCycle.SingleInstance); reg.RegisterType <SubscriptionService, ISubscriptionService>(LifeCycle.SingleInstance); RegisterSubscribersByType(reg, typeFinder, typeof(IEventSubscriber <>)); RegisterSubscribersByType(reg, typeFinder, typeof(IEventAsyncSubscriber <>)); }
public static IIocRegistrator RegisterManySingleton( this IIocRegistrator registrator, IEnumerable <Type> implementationTypes, bool autoInjectProperty = false) { return(registrator.RegisterMany( implementationTypes, autoInjectProperty, DependencyLifeTime.Singleton)); }
/// <summary> /// Registers a singleton service of the type specified in TService with factory. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <typeparam name="TService">The type of the service to register.</typeparam> /// <param name="implementationFactory">The factory that creates the service.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterSingleton <TService>( this IIocRegistrator registrator, Func <IIocResolver, TService> implementationFactory) where TService : class { registrator.Register(implementationFactory, DependencyLifeTime.Singleton); return(registrator); }
/// <summary> /// Registersa singleton service of the type specified in TService with an implementation /// type specified in TImplementation. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <typeparam name="TService">The type of the service to register.</typeparam> /// <typeparam name="TImplementation">The type of the implementation to use.</typeparam> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterSingleton <TService, TImplementation>( this IIocRegistrator registrator) where TService : class where TImplementation : class, TService { registrator.Register <TService, TImplementation>(DependencyLifeTime.Singleton); return(registrator); }
public static IIocRegistrator RegisterAssembliesSingleton( this IIocRegistrator registrator, IEnumerable <Assembly> assemblies = null, Func <Type, bool> typeSelector = null, bool autoInjectProperty = false) { return(registrator.RegisterAssemblies(assemblies, typeSelector, autoInjectProperty, DependencyLifeTime.Singleton)); }
public static IIocRegistrator RegisterSingleton( this IIocRegistrator registrator, Type serviceType, Type implementationType, bool autoInjectProperty = false) { return(registrator.Register(serviceType, implementationType, autoInjectProperty, DependencyLifeTime.Singleton)); }
public static IIocRegistrator RegisterManyScoped( this IIocRegistrator registrator, IEnumerable <Type> seviceTypes, Type implementationType, bool autoInjectProperty = false) { registrator.RegisterMany(seviceTypes, implementationType, autoInjectProperty, DependencyLifeTime.Scoped); return(registrator); }
public static IIocRegistrator RegisterAssemblySingleton( this IIocRegistrator registrator, Assembly assembly, Func <Type, bool> typeSelector = null, bool autoInjectProperty = false) { Check.NotNull(assembly, nameof(assembly)); return(registrator.RegisterAssemblies(new[] { assembly }, typeSelector, autoInjectProperty, DependencyLifeTime.Singleton)); }
internal static IIocRegistrator RegisterMany( this IIocRegistrator registrator, Type implementationType, bool autoInjectProperty = false, DependencyLifeTime lifeTime = DependencyLifeTime.Transient) { registrator.RegisterMany( new[] { implementationType }, autoInjectProperty, lifeTime); return(registrator); }
private void RegisterServices(IIocRegistrator reg, ITypeFinder typeFinder) { //Extensibility RegisterPubSubComponents(reg, typeFinder); reg.RegisterType <PluginService, IPluginService>(LifeCycle.PerDependency); reg.RegisterType <PluginManager, IPluginManager>(LifeCycle.PerDependency); //Monitoring reg.RegisterType <MonitorResultService, IMonitorResultService>(LifeCycle.PerDependency); }
public static IDryIocManager AsDryIocManager(this IIocRegistrator registrator) { if (registrator is IDryIocManager iocManager) { return(iocManager); } Check.NotSupported("Application not supported DryIoc!"); return(null); }
/// <summary> /// Registers a type as self registration if it's not registered before. /// </summary> /// <param name="iocRegistror">Registrar</param> /// <param name="type">Type of the class</param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot(this IIocRegistrator iocRegistror, Type type, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) { if (iocRegistror.IsRegistered(type)) { return(false); } iocRegistror.Register(type, lifeTime); return(true); }
internal static IIocRegistrator RegisterMany <TImplementation>( this IIocRegistrator registrator, bool autoInjectProperty = false, DependencyLifeTime lifeTime = DependencyLifeTime.Transient) { registrator.AsDryIocManager().IocContainer .RegisterMany <TImplementation>( DryIocMannager.ConvertLifetimeToReuse(lifeTime), autoInjectProperty ? PropertiesAndFields.Auto : null); return(registrator); }
/// <summary> /// Registers a type as self registration if it's not registered before. /// </summary> /// <typeparam name="T">Type of the class</typeparam> /// <param name="iocRegistror">Registrar</param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot <T>(this IIocRegistrator iocRegistror, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) where T : class { if (iocRegistror.IsRegistered <T>()) { return(false); } iocRegistror.Register <T>(lifeTime); return(true); }
private void RegisterInterceptors(IIocRegistrator reg, ITypeFinder typeFinder) { reg.RegisterInstance(new TestContextInterceptor()); FindTypesByMethodReturnValueAndRegisterInterceptor <IEnumerable <ExecutionResult>, TestContextInterceptor>( reg, typeFinder); reg.RegisterInstance(new TestContextStepInterceptor()); FindTypesByMethodReturnValueAndRegisterInterceptor <ExecutionResult, TestContextStepInterceptor>(reg, typeFinder); RegisterCommanders(reg, typeFinder); }
/// <summary> /// Registers a type with it's implementation if it's not registered before. /// </summary> /// <param name="iocRegistror">Registrar</param> /// <param name="serviceType">Type of the class</param> /// <param name="implementationType">The type that implements <paramref name="serviceType"/></param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot( this IIocRegistrator iocRegistror, Type serviceType, Type implementationType, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) { if (iocRegistror.IsRegistered(serviceType)) { return(false); } iocRegistror.Register(serviceType, implementationType, lifeTime); return(true); }
/// <summary> /// Registers a type with it's implementation if it's not registered before. /// </summary> /// <typeparam name="TService">Registering type</typeparam> /// <typeparam name="TImplementation">The type that implements <see cref="TType"/></typeparam> /// <param name="iocRegistror">Registrar</param> /// <param name="lifeTime">Life time of the objects of this type</param> /// <returns>True, if registered for given implementation.</returns> public static bool RegisterIfNot <TService, TImplementation>( this IIocRegistrator iocRegistror, DependencyLifeTime lifeTime = DependencyLifeTime.Singleton) where TService : class where TImplementation : class, TService { if (iocRegistror.IsRegistered <TService>()) { return(false); } iocRegistror.Register <TService, TImplementation>(lifeTime); return(true); }
internal static IIocRegistrator RegisterMany( this IIocRegistrator registrator, IEnumerable <Type> seviceTypes, Type implementationType, bool autoInjectProperty = false, DependencyLifeTime lifeTime = DependencyLifeTime.Transient) { registrator.AsDryIocManager().IocContainer.RegisterMany( seviceTypes.ToArray(), implementationType, DryIocMannager.ConvertLifetimeToReuse(lifeTime), autoInjectProperty ? PropertiesAndFields.Auto : null); return(registrator); }
private void RegisterSubscribersByType(IIocRegistrator registrator, ITypeFinder typeFinder, Type subscriberType) { var consumerTypes = typeFinder.FindClassesOfType(subscriberType).ToArray(); foreach (var consumer in consumerTypes) { var services = consumer.FindInterfaces((type, criteria) => { var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition()); return(isMatch); }, subscriberType); registrator.RegisterType(consumer, services, LifeCycle.PerLifetime); } }
private void RegisterCommanders(IIocRegistrator reg, ITypeFinder typeFinder) { reg.RegisterInstance(new TestContextStepPartInterceptor()); var commanderTypes = typeFinder.FindClassesOfType <ICommander>(); if (!commanderTypes.Any()) { throw new AutomationException("Failed to find commander implementors. Please register commanders"); } foreach (var ct in commanderTypes) { var firstLevelCommanderInterfaces = GetFirstLevelInterfaces(ct) .Where(t => typeof(ICommander).IsAssignableFrom(t)); firstLevelCommanderInterfaces.ForEachItem(flci => reg.RegisterType(ct, flci, LifeCycle.PerDependency, interceptorTypes: new[] { typeof(TestContextStepPartInterceptor) })); } }
internal static IIocRegistrator RegisterAssemblies( this IIocRegistrator registrator, IEnumerable <Assembly> assemblies, Func <Type, bool> typeSelector, bool autoInjectProperty, DependencyLifeTime lifeTime) { Check.NotNull(registrator, nameof(registrator)); assemblies = assemblies ?? AppDomain.CurrentDomain.GetAssemblies(); var types = assemblies .SelectMany(asm => asm.DefinedTypes) .Select(typeInfo => typeInfo.AsType()) .Where(type => typeSelector?.Invoke(type) ?? true); foreach (var type in types) { registrator.RegisterMany(type, autoInjectProperty, lifeTime); } return(registrator); }
public static IIocRegistrator RegisterManySingleton <TImplementation>( this IIocRegistrator registrator, bool autoInjectProperty = false) { return(registrator.RegisterMany <TImplementation>( autoInjectProperty, DependencyLifeTime.Singleton)); }
/// <summary> /// Registers a singleton service of the type specified in TService as self registration. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <typeparam name="TService">The type of the service to register.</typeparam> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterSingleton <TService>(this IIocRegistrator registrator) where TService : class { registrator.Register <TService>(DependencyLifeTime.Singleton); return(registrator); }
/// <summary> /// Registers a scoped service of the type specified in serviceType with an implementation /// of the type specified in implementationType. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <param name="serviceType">The type of the service to register.</param> /// <param name="implementationType">The implementation type of the service.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterScoped( this IIocRegistrator registrator, Type serviceType, Type implementationType) { registrator.Register(serviceType, implementationType, DependencyLifeTime.Scoped); return(registrator); }
/// <summary> /// Registers a transient service of the type specified in serviceType as self registration. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <param name="serviceType">The type of the service to register.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterTransient( this IIocRegistrator registrator, Type serviceType) { registrator.Register(serviceType, DependencyLifeTime.Transient); return(registrator); }
/// <summary> /// Registers a singleton service of the type specified in serviceType as self registration. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <param name="serviceType">The type of the service to register.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterSingleton( this IIocRegistrator registrator, Type serviceType) { registrator.Register(serviceType, DependencyLifeTime.Singleton); return(registrator); }
/// <summary> /// Registers a open scope or singleton service of the type /// specified in TService with it's implementation instacne. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <typeparam name="TService">The type of the service to register.</typeparam> /// <param name="instance">Implementation instacne.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterInstanceFluent <TService>( this IIocRegistrator registrator, TService instance) { registrator.RegisterInstance(instance); return(registrator); }
/// <summary> /// Registers a open scope or singleton service of the type /// specified in serviceType with it's implementation instacne. /// </summary> /// <param name="registrator">The <see cref="IIocRegistrator"/> to regist the service to.</param> /// <param name="serviceType">The type of the service to register.</param> /// <param name="instance">Implementation instacne.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IIocRegistrator RegisterInstanceFluent( this IIocRegistrator registrator, Type serviceType, object instance) { registrator.RegisterInstance(serviceType, instance); return(registrator); }