public void ConfigureContainer(ContainerBuilder containerBuilder, IConfiguration configuration)
        {
            var typeFinder = new AppDomainTypeFinder();

            containerBuilder.RegisterType <HarFluentValidationValidatorFactory>().As <IValidatorFactory>().InstancePerLifetimeScope();

            containerBuilder.RegisterAssemblyTypes(typeFinder.GetAssemblies().ToArray()).AsClosedTypesOf(typeof(IValidator <>)).InstancePerLifetimeScope();
        }
Exemple #2
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var typeFinder = new AppDomainTypeFinder();

            foreach (var item in typeFinder.GetAssemblies())
            {
                var typesToRegister = item.GetTypes()
                                      .Where(type => !String.IsNullOrEmpty(type.Namespace))
                                      .Where(type => type.BaseType != null && type.BaseType.IsGenericType &&
                                             type.BaseType.GetGenericTypeDefinition() == typeof(IkEntityTypeConfiguration <>));
                foreach (var type in typesToRegister)
                {
                    dynamic configurationInstance = Activator.CreateInstance(type);
                    modelBuilder.Configurations.Add(configurationInstance);
                }
            }

            base.OnModelCreating(modelBuilder);
        }
Exemple #3
0
        public void Register(IServiceCollection services)
        {
            var typeFinder = new AppDomainTypeFinder();
            var assemblies = typeFinder.GetAssemblies();

            //Register myservice
            typeFinder.FindInterfacesOfType(typeof(IBaseService <>), assemblies)
            .ToList()
            .ForEach(x =>
            {
                if (x != typeof(IBaseService <>))
                {
                    typeFinder.FindClassesOfType(x)
                    .ToList()
                    .ForEach(t =>
                    {
                        services.AddScoped(x, t);
                    });
                }
            });

            //Event
            services.AddScoped <ISubscriptionService, SubscriptionService>();
            services.AddScoped <IEventPublisher, EventPublisher>();

            //Register Consumers
            typeFinder.FindClassesOfType(typeof(IConsumer <>), assemblies)
            .ToList()
            .ForEach(x =>
            {
                x.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>))
                .ToList()
                .ForEach(t =>
                {
                    services.AddScoped(t, x);
                });
            });
        }
Exemple #4
0
        /// <summary>
        /// Create a new Automapper type adapter factory
        /// </summary>
        public AutomapperTypeAdapterFactory()
        {
            //scan all assemblies finding Automapper Profile
            ITypeFinder finder = new AppDomainTypeFinder();

            var profiles = finder.GetAssemblies()
                           .SelectMany(a => a.GetTypes())
                           .Where(t => t.BaseType == typeof(Profile));

            Mapper.Initialize(cfg =>
            {
                foreach (var item in profiles)
                {
                    if (item.FullName != "AutoMapper.SelfProfiler`2" & (!item.FullName.StartsWith("AutoMapper.Configuration")))
                    {
                        cfg.AddProfile(Activator.CreateInstance(item) as Profile);
                    }
                }
            });
        }