Exemplo n.º 1
0
 public static IIocRegistrator RegisterSingleton <TService, TImplementation>(
     this IIocRegistrator registrator, bool autoInjectProperty = false)
     where TImplementation : TService
 {
     return(registrator.Register <TService, TImplementation>(
                autoInjectProperty, DependencyLifeTime.Singleton));
 }
Exemplo n.º 2
0
 public static IIocRegistrator RegisterManyTransient(
     this IIocRegistrator registrator,
     Type implementationType,
     bool autoInjectProperty = false)
 {
     return(registrator.RegisterMany(
                implementationType, autoInjectProperty, DependencyLifeTime.Transient));
 }
Exemplo n.º 3
0
        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 <>));
        }
Exemplo n.º 4
0
 public static IIocRegistrator RegisterManySingleton(
     this IIocRegistrator registrator,
     IEnumerable <Type> implementationTypes,
     bool autoInjectProperty = false)
 {
     return(registrator.RegisterMany(
                implementationTypes, autoInjectProperty, DependencyLifeTime.Singleton));
 }
Exemplo n.º 5
0
 /// <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);
 }
Exemplo n.º 6
0
 /// <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);
 }
Exemplo n.º 7
0
 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));
 }
Exemplo n.º 8
0
 public static IIocRegistrator RegisterSingleton(
     this IIocRegistrator registrator,
     Type serviceType,
     Type implementationType,
     bool autoInjectProperty = false)
 {
     return(registrator.Register(serviceType, implementationType,
                                 autoInjectProperty, DependencyLifeTime.Singleton));
 }
Exemplo n.º 9
0
 public static IIocRegistrator RegisterManyScoped(
     this IIocRegistrator registrator,
     IEnumerable <Type> seviceTypes,
     Type implementationType,
     bool autoInjectProperty = false)
 {
     registrator.RegisterMany(seviceTypes,
                              implementationType, autoInjectProperty, DependencyLifeTime.Scoped);
     return(registrator);
 }
Exemplo n.º 10
0
 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));
 }
Exemplo n.º 11
0
 internal static IIocRegistrator RegisterMany(
     this IIocRegistrator registrator,
     Type implementationType,
     bool autoInjectProperty     = false,
     DependencyLifeTime lifeTime = DependencyLifeTime.Transient)
 {
     registrator.RegisterMany(
         new[] { implementationType }, autoInjectProperty, lifeTime);
     return(registrator);
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public static IDryIocManager AsDryIocManager(this IIocRegistrator registrator)
        {
            if (registrator is IDryIocManager iocManager)
            {
                return(iocManager);
            }

            Check.NotSupported("Application not supported DryIoc!");
            return(null);
        }
Exemplo n.º 14
0
        /// <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);
        }
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
        /// <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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        /// <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);
        }
Exemplo n.º 19
0
        /// <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);
        }
Exemplo n.º 20
0
 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);
 }
Exemplo n.º 21
0
        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);
            }
        }
Exemplo n.º 22
0
        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) }));
            }
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
 public static IIocRegistrator RegisterManySingleton <TImplementation>(
     this IIocRegistrator registrator, bool autoInjectProperty = false)
 {
     return(registrator.RegisterMany <TImplementation>(
                autoInjectProperty, DependencyLifeTime.Singleton));
 }
Exemplo n.º 25
0
 /// <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);
 }
Exemplo n.º 26
0
 /// <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);
 }
Exemplo n.º 27
0
 /// <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);
 }
Exemplo n.º 28
0
 /// <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);
 }
Exemplo n.º 29
0
 /// <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);
 }
Exemplo n.º 30
0
 /// <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);
 }