mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-18 13:11:16 +08:00
46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Xunit.DependencyInjection.Logging;
|
|
using Util.Aop;
|
|
using Util.Data.EntityFrameworkCore;
|
|
using Util.Helpers;
|
|
using Util.Sessions;
|
|
using Util.Tests.Infrastructure;
|
|
using Util.Tests.UnitOfWorks;
|
|
|
|
namespace Util.Applications {
|
|
/// <summary>
|
|
/// 启动配置
|
|
/// </summary>
|
|
public class Startup {
|
|
/// <summary>
|
|
/// 配置主机
|
|
/// </summary>
|
|
public void ConfigureHost( IHostBuilder hostBuilder ) {
|
|
Environment.SetDevelopment();
|
|
hostBuilder.ConfigureDefaults( null )
|
|
.AsBuild()
|
|
.AddAop()
|
|
.AddSqlServerUnitOfWork<ITestUnitOfWork, SqlServerUnitOfWork>( Config.GetConnectionString( "connection" ) )
|
|
.AddUtil();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置服务
|
|
/// </summary>
|
|
public void ConfigureServices( IServiceCollection services ) {
|
|
services.AddLogging( logBuilder => logBuilder.AddXunitOutput() );
|
|
services.AddSingleton<ISession, TestSession>();
|
|
InitDatabase( services );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化数据库
|
|
/// </summary>
|
|
private void InitDatabase( IServiceCollection services ) {
|
|
var unitOfWork = services.BuildServiceProvider().GetService<ITestUnitOfWork>();
|
|
unitOfWork.EnsureDeleted();
|
|
unitOfWork.EnsureCreated();
|
|
}
|
|
}
|
|
} |