private void RegisterOtherTypes(RegistrationTaskContext context) { var serviceCollection = context.Container; serviceCollection.AddScoped <IUnitOfWorkManager, UnitOfWorkManager>(); serviceCollection.AddSingleton(typeof(IBoltOnLogger <>), typeof(BoltOnNetStandardLoggerAdapter <>)); serviceCollection.AddSingleton <IBoltOnLoggerFactory, BoltOnLoggerFactory>(); }
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(); }
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)); }
public void Run(RegistrationTaskContext context) { RegisterByConvention(context); RegisterOtherTypes(context); }