Ejemplo n.º 1
0
        private void RegisterOtherTypes(RegistrationTaskContext context)
        {
            var serviceCollection = context.Container;

            serviceCollection.AddScoped <IUnitOfWorkManager, UnitOfWorkManager>();
            serviceCollection.AddSingleton(typeof(IBoltOnLogger <>), typeof(BoltOnNetStandardLoggerAdapter <>));
            serviceCollection.AddSingleton <IBoltOnLoggerFactory, BoltOnLoggerFactory>();
        }
Ejemplo n.º 2
0
        private void RunRegistrationTasks()
        {
            var registrationTaskType  = typeof(IRegistrationTask);
            var registrationTaskTypes = (from a in Assemblies
                                         from t in a.GetTypes()
                                         where registrationTaskType.IsAssignableFrom(t) &&
                                         t.IsClass
                                         select t).ToList();

            var registrationTaskContext = new RegistrationTaskContext(this);

            foreach (var type in registrationTaskTypes)
            {
                var task = Activator.CreateInstance(type) as IRegistrationTask;
                task.Run(registrationTaskContext);
            }

            RegisterPostRegistrationTasks();
        }
Ejemplo n.º 3
0
        private void RegisterByConvention(RegistrationTaskContext context)
        {
            var interfaces = (from assembly in context.Assemblies
                              from type in assembly.GetTypes()
                              where type.IsInterface
                              select type).ToList();
            var tempRegistrations = (from @interface in interfaces
                                     from assembly in context.Assemblies
                                     from type in assembly.GetTypes()
                                     where !type.IsAbstract &&
                                     type.IsClass && @interface.IsAssignableFrom(type) &&
                                     !type.GetCustomAttributes(typeof(ExcludeFromRegistrationAttribute), true).Any()
                                     select new { Interface = @interface, Implementation = type }).ToList();

            // get interfaces with only one implementation
            var registrations = (from r in tempRegistrations
                                 group r by r.Interface into grp
                                 where grp.Count() == 1
                                 select new { Interface = grp.Key, grp.First().Implementation }).ToList();

            registrations.ForEach(f => context.Container.AddTransient(f.Interface, f.Implementation));
        }
Ejemplo n.º 4
0
 public void Run(RegistrationTaskContext context)
 {
     RegisterByConvention(context);
     RegisterOtherTypes(context);
 }