Simplify MVC template web module class.

pull/732/head
Halil ibrahim Kalkan 7 years ago
parent 5a5a495ec4
commit 3e95ce3811

@ -3,7 +3,6 @@ using System.Linq;
using Localization.Resources.AbpUi; using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using MyCompanyName.MyProjectName.EntityFrameworkCore; using MyCompanyName.MyProjectName.EntityFrameworkCore;
using MyCompanyName.MyProjectName.Localization.MyProjectName; using MyCompanyName.MyProjectName.Localization.MyProjectName;
@ -21,7 +20,6 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.Data;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.Identity.Web; using Volo.Abp.Identity.Web;
using Volo.Abp.Localization; using Volo.Abp.Localization;
@ -66,40 +64,38 @@ namespace MyCompanyName.MyProjectName
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
ConfigureDatabaseServices(context.Services, configuration); ConfigureDatabaseServices();
ConfigureAutoMapper(context.Services); ConfigureAutoMapper();
ConfigureVirtualFileSystem(context.Services, hostingEnvironment); ConfigureVirtualFileSystem(hostingEnvironment);
ConfigureLocalizationServices(context.Services); ConfigureLocalizationServices();
ConfigureNavigationServices(context.Services); ConfigureNavigationServices();
ConfigureAutoApiControllers(context.Services); ConfigureAutoApiControllers();
ConfigureSwaggerServices(context.Services); ConfigureSwaggerServices(context.Services);
} }
private static void ConfigureDatabaseServices(IServiceCollection services, IConfigurationRoot configuration) private void ConfigureDatabaseServices()
{ {
services.Configure<DbConnectionOptions>(options => //<TEMPLATE-REMOVE IF-NOT='EntityFrameworkCore'>
Configure<AbpDbContextOptions>(options =>
{ {
options.ConnectionStrings.Default = configuration.GetConnectionString("Default"); options.UseSqlServer();
}); });
//<TEMPLATE-REMOVE IF-NOT='EntityFrameworkCore'>
services.Configure<AbpDbContextOptions>(options => { options.UseSqlServer(); });
//</TEMPLATE-REMOVE> //</TEMPLATE-REMOVE>
} }
private static void ConfigureAutoMapper(IServiceCollection services) private void ConfigureAutoMapper()
{ {
services.Configure<AbpAutoMapperOptions>(options => Configure<AbpAutoMapperOptions>(options =>
{ {
options.AddProfile<MyProjectNameWebAutoMapperProfile>(); options.AddProfile<MyProjectNameWebAutoMapperProfile>();
}); });
} }
private static void ConfigureVirtualFileSystem(IServiceCollection services, IHostingEnvironment hostingEnvironment) private void ConfigureVirtualFileSystem(IHostingEnvironment hostingEnvironment)
{ {
if (hostingEnvironment.IsDevelopment()) if (hostingEnvironment.IsDevelopment())
{ {
services.Configure<VirtualFileSystemOptions>(options => Configure<VirtualFileSystemOptions>(options =>
{ {
options.FileSets.ReplaceEmbeddedByPyhsical<MyProjectNameDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}MyCompanyName.MyProjectName.Domain", Path.DirectorySeparatorChar))); options.FileSets.ReplaceEmbeddedByPyhsical<MyProjectNameDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}MyCompanyName.MyProjectName.Domain", Path.DirectorySeparatorChar)));
//<TEMPLATE-REMOVE> //<TEMPLATE-REMOVE>
@ -116,9 +112,9 @@ namespace MyCompanyName.MyProjectName
} }
} }
private static void ConfigureLocalizationServices(IServiceCollection services) private void ConfigureLocalizationServices()
{ {
services.Configure<AbpLocalizationOptions>(options => Configure<AbpLocalizationOptions>(options =>
{ {
options.Resources options.Resources
.Get<MyProjectNameResource>() .Get<MyProjectNameResource>()
@ -134,23 +130,23 @@ namespace MyCompanyName.MyProjectName
}); });
} }
private static void ConfigureNavigationServices(IServiceCollection services) private void ConfigureNavigationServices()
{ {
services.Configure<NavigationOptions>(options => Configure<NavigationOptions>(options =>
{ {
options.MenuContributors.Add(new MyProjectNameMenuContributor()); options.MenuContributors.Add(new MyProjectNameMenuContributor());
}); });
} }
private static void ConfigureAutoApiControllers(IServiceCollection services) private void ConfigureAutoApiControllers()
{ {
services.Configure<AbpAspNetCoreMvcOptions>(options => Configure<AbpAspNetCoreMvcOptions>(options =>
{ {
options.ConventionalControllers.Create(typeof(MyProjectNameApplicationModule).Assembly); options.ConventionalControllers.Create(typeof(MyProjectNameApplicationModule).Assembly);
}); });
} }
private static void ConfigureSwaggerServices(IServiceCollection services) private void ConfigureSwaggerServices(IServiceCollection services)
{ {
services.AddSwaggerGen( services.AddSwaggerGen(
options => options =>

Loading…
Cancel
Save