Пример #1
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            // var dependencyContext = DependencyContext.Default;
            // var assembliesToScan = dependencyContext.RuntimeLibraries
            //     .SelectMany(lib => lib.GetDefaultAssemblyNames(dependencyContext).Select(Assembly.Load));

            var assembliesToScan = PlatformUtils.GetAllAssemblies("Identity.Api");

            assembliesToScan = assembliesToScan as Assembly[] ?? assembliesToScan.ToArray();

            var allTypes = assembliesToScan.SelectMany(a => a.ExportedTypes).ToArray();

            var profiles = allTypes
                           .Where(t => typeof(Profile).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()) &&
                                  !t.GetTypeInfo().IsAbstract)
                           .ToArray();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AllowNullDestinationValues = true;

                foreach (var profile in profiles)
                {
                    cfg.AddProfile(profile);
                }
            });

            services.AddSingleton <IConfigurationProvider>(config);
            services.AddScoped <IMapper>(sp => new Mapper(sp.GetRequiredService <IConfigurationProvider>(), sp.GetService));
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.SetupConfiguration(Configuration);
            services.InstallServicesIn(Configuration,
                                       PlatformUtils.GetAllAssemblies("EventManagement.Installers.Tools").Concat(
                                           PlatformUtils.GetAssembliesBasedOn <Startup>()));

            var runtimeAssemblies = PlatformUtils.GetAllAssemblies(Program.AppName).ToArray();

            return(services.AddAutofacService(Container, runtimeAssemblies));
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.SetupConfiguration(Configuration);
            services.AddControllers();
            services.InstallServicesIn(Configuration,
                                       PlatformUtils.GetAllAssemblies("EventManagement.Installers.Tools").Concat(
                                           PlatformUtils.GetAssembliesBasedOn <Startup>()));

            var runtimeAssemblies = PlatformUtils.GetAllAssemblies(Program.AppName).ToArray();
            var modules           = new List <IModule>
            {
                new StandardModule(runtimeAssemblies),
                new MediatorModule(runtimeAssemblies)
            };

            return(services.AddAutofacService(Container, runtimeAssemblies, modules));
        }