/// <summary> /// Add and configure services /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <returns>Service provider</returns> public IServiceProvider ConfigureServices(IServiceCollection services, IConfiguration configuration) { //find startup configurations provided by other assemblies WebAppTypeFinder typeFinder = new WebAppTypeFinder(); System.Collections.Generic.IEnumerable <Type> startupConfigurations = typeFinder.FindClassesOfType <IVerivoxStartup>(); //create and sort instances of startup configurations IOrderedEnumerable <IVerivoxStartup> instances = startupConfigurations .Select(startup => (IVerivoxStartup)Activator.CreateInstance(startup)) .OrderBy(startup => startup.Order); //configure services foreach (IVerivoxStartup instance in instances) { instance.ConfigureServices(services, configuration); } //register dependencies VerivoxConfig config = services.BuildServiceProvider().GetService <VerivoxConfig>(); _serviceProvider = RegisterDependencies(config, services, typeFinder); //resolve assemblies here. otherwise, plugins can throw an exception when rendering views AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; return(_serviceProvider); }
public void ConfigureContainer(ContainerBuilder containerBuilder) { WebAppTypeFinder typeFinder = new WebAppTypeFinder(); System.Collections.Generic.IEnumerable <Type> startupConfigurations = typeFinder.FindClassesOfType <IVerivoxStartup>(); //register engine containerBuilder.RegisterInstance(this).As <IEngine>().SingleInstance(); //register type finder containerBuilder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); //find dependency registrars provided by other assemblies System.Collections.Generic.IEnumerable <Type> dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>(); //create and sort instances of dependency registrars IOrderedEnumerable <IDependencyRegistrar> instances = dependencyRegistrars //.Where(dependencyRegistrar => PluginManager.FindPlugin(dependencyRegistrar)?.Installed ?? true) //ignore not installed plugins .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar)) .OrderBy(dependencyRegistrar => dependencyRegistrar.Order); //register all provided dependencies foreach (IDependencyRegistrar dependencyRegistrar in instances) { dependencyRegistrar.Register(containerBuilder); } }