Esempio n. 1
0
        /// <summary>
        /// Register services in Autofac
        /// </summary>
        /// <param name="builder">The container builder instance to use</param>
        public void Register(ContainerBuilder builder)
        {
            Argument.NotNull(builder, nameof(builder));

            var serviceType = typeof(ICommandHandler <,>);

            var types = _assemblyProvider.GetLocalAssemblies()
                        .SelectMany(x => x.GetTypes())
                        .Where(x => x.IsClass == true)
                        .Where(x => x.IsGenericType == false)
                        .SelectMany(x => x.GetInterfaces(), (i, s) => (Implementor: i, Service: s))
                        .Where(x => x.Service.IsGenericType == true)
                        .Where(x => x.Service.ContainsGenericParameters == false)
                        .Where(x => x.Service.GetGenericTypeDefinition() == serviceType)
                        .ToList();

            foreach (var(implementor, service) in types)
            {
                _ = builder.RegisterType(implementor)
                    .As(service)
                    .InstancePerLifetimeScope();
            }

            var decorators = new[]
            {
                typeof(ValidateCommandHandlerDecorator <,>),
                typeof(LogExceptionCommandHandlerDecorator <,>),
                typeof(DebugCommandHandlerDecorator <,>),
            };

            foreach (var decorator in decorators)
            {
                builder.RegisterGenericDecorator(decorator, serviceType);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Register services in Autofac
        /// </summary>
        /// <param name="builder">The container builder instance to use</param>
        public void Register(ContainerBuilder builder)
        {
            Argument.NotNull(builder, nameof(builder));

            var serviceType = typeof(IBearerTokenProvider <>);

            var decoratorTypes = new Type[]
            {
                typeof(ExpiresBearerTokenProviderDecorator <>),
                typeof(CacheBearerTokenProviderDecorator <>),
                typeof(EnsureSuccessBearerTokenProviderDecorator <>),
            };

            var types = _assemblyProvider.GetLocalAssemblies()
                        .SelectMany(x => x.GetTypes())
                        .Where(x => x.IsClass == true)
                        .Where(x => x.IsGenericType == false)
                        .SelectMany(x => x.GetInterfaces(), (i, s) => (Implementor: i, Service: s))
                        .Where(x => x.Service.IsGenericType == true)
                        .Where(x => x.Service.ContainsGenericParameters == false)
                        .Where(x => x.Service.GetGenericTypeDefinition() == serviceType)
                        .ToList();

            foreach (var(implementor, service) in types)
            {
                _ = builder.RegisterType(implementor)
                    .As(service)
                    .InstancePerLifetimeScope();
            }

            foreach (var decoratorType in decoratorTypes)
            {
                builder.RegisterGenericDecorator(decoratorType, serviceType);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Register services in Autofac
        /// </summary>
        /// <param name="builder">The container builder instance to use</param>
        public void Register(ContainerBuilder builder)
        {
            Argument.NotNull(builder, nameof(builder));

            var serviceType = typeof(IValidator <>);

            _ = builder.RegisterGeneric(typeof(Validator <>))
                .As(serviceType)
                .InstancePerLifetimeScope();

            var types = _assemblyProvider.GetLocalAssemblies()
                        .SelectMany(x => x.GetTypes())
                        .Where(x => x.IsClass == true)
                        .Where(x => x.IsGenericType == false)
                        .SelectMany(x => x.GetInterfaces(), (i, s) => (Implementor: i, Service: s))
                        .Where(x => x.Service.IsGenericType == true)
                        .Where(x => x.Service.ContainsGenericParameters == false)
                        .Where(x => x.Service.GetGenericTypeDefinition() == serviceType)
                        .ToList();

            foreach (var(implementor, service) in types)
            {
                _ = builder.RegisterType(implementor)
                    .As(service)
                    .InstancePerLifetimeScope();
            }

            _ = builder.RegisterGenericComposite(typeof(CompositeValidator <>), serviceType)
                .InstancePerLifetimeScope();
        }
Esempio n. 4
0
        /// <summary>
        /// Register dependencies in Autofac
        /// </summary>
        /// <param name="builder">The builder</param>
        public void Register(ContainerBuilder builder)
        {
            Argument.NotNull(builder, nameof(builder));

            var types = _assemblyProvider.GetLocalAssemblies()
                        .SelectMany(x => x.GetTypes())
                        .Where(x => x.IsClass == true)
                        .Where(x => x.IsAbstract == false)
                        .Where(x => typeof(IExample).IsAssignableFrom(x))
                        .ToList();

            foreach (var type in types)
            {
                _ = builder.RegisterType(type)
                    .AsSelf()
                    .InstancePerLifetimeScope();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Register dependencies in Autofac
        /// </summary>
        /// <param name="builder">The builder</param>
        public void Register(ContainerBuilder builder)
        {
            Argument.NotNull(builder, nameof(builder));

            var serviceType = typeof(IBearerTokenProvider <>);

            /*
             * The decorators to apply, from inner to outer
             * the first decorator acts directly on BearerTokenProvider
             * the last decorator is the one you get when resolving an instance of IBearerTokenProvider
             *
             */
            var decoratorTypes = new Type[]
            {
                typeof(ExpiresBearerTokenProviderDecorator <>),
                typeof(LogToConsoleBearerTokenProviderDecorator <>),
                typeof(CacheBearerTokenProviderDecorator <>),
                typeof(EnsureSuccessBearerTokenProviderDecorator <>),
            };

            var types = _assemblyProvider.GetLocalAssemblies()
                        .SelectMany(x => x.GetTypes())
                        .Where(x => x.IsClass == true)
                        .Where(x => x.IsGenericType == false)
                        .SelectMany(x => x.GetInterfaces(), (i, s) => (Implementor: i, Service: s))
                        .Where(x => x.Service.IsGenericType == true)
                        .Where(x => x.Service.ContainsGenericParameters == false)
                        .Where(x => x.Service.GetGenericTypeDefinition() == typeof(IBearerTokenProvider <>))
                        .ToList();

            foreach (var(implementor, service) in types)
            {
                _ = builder.RegisterType(implementor)
                    .As(service)
                    .InstancePerLifetimeScope();
            }

            foreach (var decoratorType in decoratorTypes)
            {
                builder.RegisterGenericDecorator(decoratorType, serviceType);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Retrieve a list of local assemblies
 /// </summary>
 /// <returns>The list of local assemblies</returns>
 public IReadOnlyList <Assembly> GetLocalAssemblies()
 {
     return(_provider.GetLocalAssemblies());
 }