Skip to content

Commit

Permalink
add BusinessServiceModule
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi committed Feb 24, 2020
1 parent b0ab444 commit e3e5571
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
21 changes: 11 additions & 10 deletions ActivityReservation.Business/BLLCollection.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ActivityReservation.Database;
using ActivityReservation.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using WeihanLi.EntityFramework;

namespace ActivityReservation.Business
Expand Down Expand Up @@ -91,16 +92,16 @@ public static class BusinessExtensions
{
public static IServiceCollection AddBLL(this IServiceCollection services)
{
services.AddScoped<IBLLUser, BLLUser>();
services.AddScoped<IBLLBlockType, BLLBlockType>();
services.AddScoped<IBLLBlockEntity, BLLBlockEntity>();
services.AddScoped<IBLLOperationLog, BLLOperationLog>();
services.AddScoped<IBLLReservation, BLLReservation>();
services.AddScoped<IBLLReservationPlace, BLLReservationPlace>();
services.AddScoped<IBLLReservationPeriod, BLLReservationPeriod>();
services.AddScoped<IBLLSystemSettings, BLLSystemSettings>();
services.AddScoped<IBLLNotice, BLLNotice>();
services.AddScoped<IBLLDisabledPeriod, BLLDisabledPeriod>();
services.TryAddScoped<IBLLUser, BLLUser>();
services.TryAddScoped<IBLLBlockType, BLLBlockType>();
services.TryAddScoped<IBLLBlockEntity, BLLBlockEntity>();
services.TryAddScoped<IBLLOperationLog, BLLOperationLog>();
services.TryAddScoped<IBLLReservation, BLLReservation>();
services.TryAddScoped<IBLLReservationPlace, BLLReservationPlace>();
services.TryAddScoped<IBLLReservationPeriod, BLLReservationPeriod>();
services.TryAddScoped<IBLLSystemSettings, BLLSystemSettings>();
services.TryAddScoped<IBLLNotice, BLLNotice>();
services.TryAddScoped<IBLLDisabledPeriod, BLLDisabledPeriod>();
return services;
}
}
Expand Down
3 changes: 2 additions & 1 deletion ActivityReservation.Business/BLLCollection.tt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using ActivityReservation.Database;
using ActivityReservation.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using WeihanLi.EntityFramework;

namespace ActivityReservation.Business
Expand Down Expand Up @@ -49,7 +50,7 @@ namespace ActivityReservation.Business
foreach (var item in types)
{
#>
services.AddScoped<IBLL<#= item #>, BLL<#= item #>>();
services.TryAddScoped<IBLL<#= item #>, BLL<#= item #>>();
<#
}
#>
Expand Down
3 changes: 2 additions & 1 deletion ActivityReservation.Helper/Helpers/DatabaseInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static void Initialize(this IServiceProvider serviceProvider)
var dbContext = scope.ServiceProvider.GetRequiredService<ReservationDbContext>();
dbContext.Database.EnsureCreated();

// TODO: update with dbContext.Database.IsRelational when new ef core released, https://github.com/dotnet/efcore/pull/19521
// TODO: update with dbContext.Database.IsRelational when new ef core released
// https://github.com/dotnet/efcore/pull/19521
if (dbContext.Database.ProviderName.EqualsIgnoreCase("Microsoft.EntityFrameworkCore.InMemory"))
{
if (!dbContext.Users.AsNoTracking().Any())
Expand Down
26 changes: 26 additions & 0 deletions ActivityReservation.Helper/Services/BusinessServiceModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ActivityReservation.Business;
using ActivityReservation.Events;
using ActivityReservation.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using WeihanLi.Common.Event;
using WeihanLi.EntityFramework;
using WeihanLi.Extensions;

namespace ActivityReservation.Services
{
public class BusinessServiceModule : IServiceModule
{
public void ConfigureServices(IServiceCollection services)
{
services.AddEFRepository();
services.AddBLL();
services.TryAddScoped<ReservationHelper>();
services.TryAddSingleton<CaptchaVerifyHelper>();
services.TryAddSingleton<OperLogHelper>();

// register eventHandlers
services.RegisterAssemblyTypes(t => !t.IsAbstract && t.IsClass && t.IsAssignableTo<IEventHandler>(), typeof(NoticeViewEventHandler).Assembly);
}
}
}
17 changes: 3 additions & 14 deletions ActivityReservation/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using ActivityReservation.Business;
using ActivityReservation.Common;
using ActivityReservation.Database;
using ActivityReservation.Events;
Expand Down Expand Up @@ -33,7 +32,6 @@
using WeihanLi.Common.Http;
using WeihanLi.Common.Logging;
using WeihanLi.Common.Logging.Serilog;
using WeihanLi.EntityFramework;
using WeihanLi.Extensions;
using WeihanLi.Extensions.Localization.Json;
using WeihanLi.Npoi;
Expand Down Expand Up @@ -136,12 +134,6 @@ public void ConfigureServices(IServiceCollection services)
options.AppSecret = Configuration["Tencent:Captcha:AppSecret"];
});

services.AddEFRepository();
services.AddBLL();

services.AddSingleton<OperLogHelper>();
services.AddScoped<ReservationHelper>();

// registerApplicationSettingService
services.TryAddSingleton<IApplicationSettingService, ApplicationSettingInRedisService>();

Expand All @@ -164,8 +156,6 @@ public void ConfigureServices(IServiceCollection services)
.ConfigurePrimaryHttpMessageHandler(() => new NoProxyHttpClientHandler());
services.TryAddSingleton<WechatAPI.Helper.WeChatHelper>();

services.TryAddSingleton<CaptchaVerifyHelper>();

services.AddRedisConfig(options =>
{
options.RedisServers = new[]
Expand All @@ -184,10 +174,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IEventBus, RedisEventBus>();
services.AddSingleton<IEventStore, EventStoreInRedis>();

//register EventHandlers
services.AddSingleton<OperationLogEventHandler>();
services.AddSingleton<NoticeViewEventHandler>();

services.AddHostedService<RemoveOverdueReservationService>();
// services.AddHostedService<CronLoggingTest>();

Expand Down Expand Up @@ -235,6 +221,9 @@ public void ConfigureServices(IServiceCollection services)
options.IncludeXmlComments(System.IO.Path.Combine(AppContext.BaseDirectory, $"{typeof(API.NoticeController).Assembly.GetName().Name}.xml"), true);
});

// RegisterAssemblyModules
services.RegisterAssemblyModules();

// SetDependencyResolver
DependencyResolver.SetDependencyResolver(services);
}
Expand Down

0 comments on commit e3e5571

Please sign in to comment.