public static IServiceCollection AddAutoMapper(this IServiceCollection services) { var hostingEnvironment = services.BuildServiceProvider().GetService <IHostingEnvironment>(); var autoMapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new ApiAutoMapperProfile()); cfg.AddProfile(new DomainAutoMapperProfile()); cfg.AddProfile(new ReportingAutoMapperProfile()); foreach (var profile in AppLoader.Instance(hostingEnvironment).AppAssemblies.GetImplementationsOf <Profile>()) { cfg.AddProfile(profile); } }); services.AddSingleton(sp => autoMapperConfig.CreateMapper()); return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); services.AddTransient <IContextService, ContextService>(); var hostingEnvironment = services.BuildServiceProvider().GetService <IHostingEnvironment>(); services.AddOptions(); services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings")); services.AddApplicationInsightsTelemetry(Configuration); services.AddEntityFramework(Configuration); services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddMvc() .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix) .AddDataAnnotationsLocalization() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }) .AddRazorOptions(options => { foreach (var assembly in AppLoader.Instance(hostingEnvironment).AppAssemblies) { var reference = MetadataReference.CreateFromFile(assembly.Location); options.AdditionalCompilationReferences.Add(reference); } }); services.Configure <RazorViewEngineOptions>(options => { foreach (var assembly in AppLoader.Instance(hostingEnvironment).AppAssemblies) { var embeddedFileProvider = new EmbeddedFileProvider(assembly, assembly.GetName().Name); options.FileProviders.Add(embeddedFileProvider); } options.ViewLocationExpanders.Add(new ViewLocationExpander()); }); services.AddAutoMapper(); foreach (var startup in AppLoader.Instance(hostingEnvironment).AppAssemblies.GetImplementationsOf <Mvc.Apps.IStartup>()) { startup.ConfigureServices(services); } var builder = new ContainerBuilder(); foreach (var module in AppLoader.Instance(hostingEnvironment).AppAssemblies.GetImplementationsOf <IModule>()) { builder.RegisterModule(module); } builder.RegisterModule(new AutofacModule()); builder.Populate(services); var container = builder.Build(); return(container.Resolve <IServiceProvider>()); }
public void Configure(IApplicationBuilder app, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, ISiteInstallationService siteInstallationService, IThemeInstallationService themeInstallationService, ISiteRepository siteRepository, IQueryDispatcher queryDispatcher) { app.EnsureDbCreated(); app.EnsureIdentityCreatedAsync(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseStatusCodePagesWithRedirects("~/error/{0}"); if (hostingEnvironment.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/error/500"); } app.UseTheme(); app.UseStaticFiles(); foreach (var theme in queryDispatcher.DispatchAsync <GetActiveThemes, IEnumerable <ThemeInfo> >(new GetActiveThemes()).Result) { var contentPath = Path.Combine(hostingEnvironment.ContentRootPath, "Themes", theme.Folder, "wwwroot"); if (Directory.Exists(contentPath)) { app.UseStaticFiles(new StaticFileOptions { RequestPath = "/Themes/" + theme.Folder, FileProvider = new PhysicalFileProvider(contentPath) }); } } foreach (var appDescriptor in AppLoader.Instance(hostingEnvironment).AppDescriptors) { var contentPath = Path.Combine(hostingEnvironment.ContentRootPath, "Apps", appDescriptor.Folder, "wwwroot"); if (Directory.Exists(contentPath)) { app.UseStaticFiles(new StaticFileOptions { RequestPath = "/" + appDescriptor.Folder, FileProvider = new PhysicalFileProvider(contentPath) }); } } foreach (var startup in AppLoader.Instance(hostingEnvironment).AppAssemblies.GetImplementationsOf <Mvc.Apps.IStartup>()) { startup.Configure(app); } var applicationPartManager = app.ApplicationServices.GetRequiredService <ApplicationPartManager>(); Parallel.ForEach(AppLoader.Instance(hostingEnvironment).AppAssemblies, assembly => { applicationPartManager.ApplicationParts.Add(new AssemblyPart(assembly)); }); app.UseIdentity(); themeInstallationService.EnsureThemeInstalled(new CreateTheme { Name = "Default", Description = "Default Theme", Folder = "Default" }); siteInstallationService.VerifySiteInstallation(); var site = siteRepository.GetByName("Default"); var activeLanguages = queryDispatcher.DispatchAsync <GetAllActive, IEnumerable <LanguageInfo> >(new GetAllActive { SiteId = site.Id }).Result; app.AddRoutes(); app.AddLocalisation(activeLanguages); }
public void Configure(IApplicationBuilder app, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, ISiteInstallationService siteInstallationService, IAppInstallationService appInstallationService, IMembershipInstallationService membershipInstallationService, ISiteRepository siteRepository, ILanguageFacade languageFacade, IPageFacade pageFacade) { membershipInstallationService.VerifyUserCreation(); appInstallationService.VerifyAppInstallation(); siteInstallationService.VerifySiteInstallation(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); app.UseStatusCodePagesWithRedirects("~/error/{0}"); if (hostingEnvironment.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/error/500"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); foreach (var appDescriptor in AppLoader.Instance(hostingEnvironment).AppDescriptors) { var contentPath = Path.Combine(hostingEnvironment.ContentRootPath, "Apps", appDescriptor.Folder, "wwwroot"); if (Directory.Exists(contentPath)) { app.UseStaticFiles(new StaticFileOptions { RequestPath = "/" + appDescriptor.Folder, FileProvider = new PhysicalFileProvider(contentPath) }); } } foreach (var startup in AppLoader.Instance(hostingEnvironment).AppAssemblies.GetTypes <Mvc.Apps.IStartup>()) { startup.Configure(app); } var applicationPartManager = app.ApplicationServices.GetRequiredService <ApplicationPartManager>(); Parallel.ForEach(AppLoader.Instance(hostingEnvironment).AppAssemblies, assembly => { applicationPartManager.ApplicationParts.Add(new AssemblyPart(assembly)); }); app.UseIdentity(); var site = siteRepository.GetByName("Default"); var activeLanguages = languageFacade.GetAllActiveAsync(site.Id).Result; app.AddRoutes(); app.AddLocalisation(activeLanguages); }