Refactor MVC template.

pull/1128/head
Halil ibrahim Kalkan 7 years ago
parent bd775316f5
commit 7d764f3595

@ -1,6 +1,9 @@
using MyCompanyName.MyProjectName.Localization.MyProjectName;
using Microsoft.Extensions.DependencyInjection;
using MyCompanyName.MyProjectName.Localization.MyProjectName;
using Volo.Abp;
using Volo.Abp.AuditLogging;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Data;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Identity;
using Volo.Abp.Localization;
@ -10,6 +13,7 @@ using Volo.Abp.MultiTenancy;
using Volo.Abp.PermissionManagement.Identity;
using Volo.Abp.SettingManagement;
using Volo.Abp.TenantManagement;
using Volo.Abp.Threading;
using Volo.Abp.VirtualFileSystem;
namespace MyCompanyName.MyProjectName
@ -45,5 +49,23 @@ namespace MyCompanyName.MyProjectName
options.IsEnabled = MyProjectNameConsts.IsMultiTenancyEnabled;
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedDatabase(context);
}
private void SeedDatabase(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
AsyncHelper.RunSync(async () =>
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>()
.SeedAsync();
});
}
}
}
}

@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
@ -33,6 +34,11 @@ namespace MyCompanyName.MyProjectName.EntityFrameworkCore
*/
options.AddDefaultRepositories(includeAllEntities: true);
});
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
}
}
}

@ -1,5 +1,4 @@
using System.IO;
using Localization.Resources.AbpUi;
using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
@ -7,6 +6,7 @@ using MyCompanyName.MyProjectName.EntityFrameworkCore;
using MyCompanyName.MyProjectName.Localization.MyProjectName;
using MyCompanyName.MyProjectName.Menus;
using Swashbuckle.AspNetCore.Swagger;
using System.IO;
using Volo.Abp;
using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Mvc;
@ -17,19 +17,14 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
using Volo.Abp.Data;
using Volo.Abp.Identity.Web;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement.Web;
using Volo.Abp.Threading;
using Volo.Abp.TenantManagement.Web;
using Volo.Abp.UI;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;
using Volo.Abp.TenantManagement.Web;
//<TEMPLATE-REMOVE IF-NOT='EntityFrameworkCore'>
using Volo.Abp.EntityFrameworkCore;
//</TEMPLATE-REMOVE>
namespace MyCompanyName.MyProjectName
{
@ -62,7 +57,6 @@ namespace MyCompanyName.MyProjectName
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
ConfigureDatabaseServices();
ConfigureAutoMapper();
ConfigureVirtualFileSystem(hostingEnvironment);
ConfigureLocalizationServices();
@ -71,16 +65,6 @@ namespace MyCompanyName.MyProjectName
ConfigureSwaggerServices(context.Services);
}
private void ConfigureDatabaseServices()
{
//<TEMPLATE-REMOVE IF-NOT='EntityFrameworkCore'>
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
//</TEMPLATE-REMOVE>
}
private void ConfigureAutoMapper()
{
Configure<AbpAutoMapperOptions>(options =>
@ -110,7 +94,7 @@ namespace MyCompanyName.MyProjectName
options.FileSets.ReplaceEmbeddedByPhysical<AbpPermissionManagementWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}permission-management{0}src{0}Volo.Abp.PermissionManagement.Web", Path.DirectorySeparatorChar)));
options.FileSets.ReplaceEmbeddedByPhysical<AbpIdentityWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}identity{0}src{0}Volo.Abp.Identity.Web", Path.DirectorySeparatorChar)));
options.FileSets.ReplaceEmbeddedByPhysical<AbpAccountWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}account{0}src{0}Volo.Abp.Account.Web", Path.DirectorySeparatorChar)));
//</TEMPLATE-REMOVE>
//</TEMPLATE-REMOVE>
});
}
}
@ -153,7 +137,7 @@ namespace MyCompanyName.MyProjectName
services.AddSwaggerGen(
options =>
{
options.SwaggerDoc("v1", new Info {Title = "MyProjectName API", Version = "v1"});
options.SwaggerDoc("v1", new Info { Title = "MyProjectName API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
}
@ -193,21 +177,6 @@ namespace MyCompanyName.MyProjectName
app.UseAuditing();
app.UseMvcWithDefaultRouteAndArea();
SeedDatabase(context);
}
private static void SeedDatabase(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
AsyncHelper.RunSync(async () =>
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>()
.SeedAsync();
});
}
}
}
}

@ -38,11 +38,6 @@ namespace MyCompanyName.MyProjectName
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
_sqliteConnection.Dispose();
@ -64,15 +59,5 @@ namespace MyCompanyName.MyProjectName
return connection;
}
private static void SeedTestData(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
.GetRequiredService<MyProjectNameTestDataBuilder>()
.Build();
}
}
}
}

@ -1,28 +1,17 @@
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName
{
public class MyProjectNameTestDataBuilder : ITransientDependency
public class MyProjectNameTestDataSeedContributor : IDataSeedContributor, ITransientDependency
{
private readonly IDataSeeder _dataSeeder;
public MyProjectNameTestDataBuilder(IDataSeeder dataSeeder)
{
_dataSeeder = dataSeeder;
}
public void Build()
public Task SeedAsync(DataSeedContext context)
{
AsyncHelper.RunSync(BuildInternalAsync);
}
/* Seed additional test data...
*/
public async Task BuildInternalAsync()
{
await _dataSeeder.SeedAsync();
return Task.CompletedTask;
}
}
}

@ -4,17 +4,12 @@ using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using MyCompanyName.MyProjectName.Localization.MyProjectName;
using MyCompanyName.MyProjectName.Menus;
using Volo.Abp;
using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.TestBase;
using Volo.Abp.Identity.Web;
using Volo.Abp.Localization;
using Volo.Abp.Localization.Resources.AbpValidation;
using Volo.Abp.Modularity;
@ -24,10 +19,8 @@ namespace MyCompanyName.MyProjectName
{
[DependsOn(
typeof(AbpAspNetCoreTestBaseModule),
typeof(MyProjectNameApplicationTestModule),
typeof(AbpIdentityWebModule),
typeof(AbpAccountWebModule),
typeof(AbpAspNetCoreMvcUiBasicThemeModule)
typeof(MyProjectNameWebModule),
typeof(MyProjectNameApplicationTestModule)
)]
public class MyProjectNameWebTestModule : AbpModule
{

@ -0,0 +1,16 @@
using System.Threading.Tasks;
using Shouldly;
using Xunit;
namespace MyCompanyName.MyProjectName.Pages
{
public class Index_Tests : MyProjectNameWebTestBase
{
[Fact]
public async Task Welcome_Page()
{
var response = await GetResponseAsStringAsync("/");
response.ShouldNotBeNull();
}
}
}

@ -1,23 +0,0 @@
using System.Threading.Tasks;
using Shouldly;
using Xunit;
namespace MyCompanyName.MyProjectName.Samples
{
public class SampleWebTest : MyProjectNameWebTestBase
{
[Fact(Skip = "This is disabled since not working")]
public async Task Welcome_Page()
{
var response = await GetResponseAsStringAsync("/");
response.ShouldNotBeNull();
}
[Fact(Skip = "This is disabled since not working")]
public async Task Login_Page()
{
var response = await GetResponseAsStringAsync("/Account/Login/");
response.ShouldNotBeNull();
}
}
}
Loading…
Cancel
Save