Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/di transform config #17

Merged
merged 2 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 2 additions & 47 deletions ef-app_backend-dotnet-core.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7AC305D7-5603-4073-8893-5104847367AB}"
EndProject
Expand All @@ -19,14 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eurofurence.App.Server.Serv
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eurofurence.App.Server.Web", "src\Eurofurence.App.Server.Web\Eurofurence.App.Server.Web.csproj", "{16CBDB12-56E7-4B6C-BDF6-7B55FC35BE27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eurofurence.App.Tools.EventScheduleImporter", "src\Eurofurence.App.Tools.EventScheduleImporter\Eurofurence.App.Tools.EventScheduleImporter.csproj", "{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Importers", "Importers", "{8907097C-8D6C-4F01-8CA3-871C6489171F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eurofurence.App.Tools.KnowledgeBaseImporter", "src\Eurofurence.App.Tools.KnowledgeBaseImporter\Eurofurence.App.Tools.KnowledgeBaseImporter.csproj", "{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eurofurence.App.Tools.DealersDenPackageImporter", "src\Eurofurence.App.Tools.DealersDenPackageImporter\Eurofurence.App.Tools.DealersDenPackageImporter.csproj", "{E5822696-816F-4865-B831-7FE06C42202B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eurofurence.App.Tools.CliToolBox", "src\Eurofurence.App.Tools.CliToolBox\Eurofurence.App.Tools.CliToolBox.csproj", "{FCEBCE71-0EA6-4F25-9BD6-A43A3E016D68}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{07D37E4D-3609-4732-8BED-7C3F69694CF0}"
Expand Down Expand Up @@ -117,42 +111,6 @@ Global
{16CBDB12-56E7-4B6C-BDF6-7B55FC35BE27}.Release|x64.Build.0 = Release|Any CPU
{16CBDB12-56E7-4B6C-BDF6-7B55FC35BE27}.Release|x86.ActiveCfg = Release|Any CPU
{16CBDB12-56E7-4B6C-BDF6-7B55FC35BE27}.Release|x86.Build.0 = Release|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Debug|x64.ActiveCfg = Debug|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Debug|x64.Build.0 = Debug|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Debug|x86.ActiveCfg = Debug|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Debug|x86.Build.0 = Debug|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Release|Any CPU.Build.0 = Release|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Release|x64.ActiveCfg = Release|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Release|x64.Build.0 = Release|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Release|x86.ActiveCfg = Release|Any CPU
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886}.Release|x86.Build.0 = Release|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Debug|x64.ActiveCfg = Debug|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Debug|x64.Build.0 = Debug|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Debug|x86.ActiveCfg = Debug|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Debug|x86.Build.0 = Debug|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Release|Any CPU.Build.0 = Release|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Release|x64.ActiveCfg = Release|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Release|x64.Build.0 = Release|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Release|x86.ActiveCfg = Release|Any CPU
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7}.Release|x86.Build.0 = Release|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Debug|x64.ActiveCfg = Debug|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Debug|x64.Build.0 = Debug|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Debug|x86.ActiveCfg = Debug|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Debug|x86.Build.0 = Debug|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Release|Any CPU.Build.0 = Release|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Release|x64.ActiveCfg = Release|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Release|x64.Build.0 = Release|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Release|x86.ActiveCfg = Release|Any CPU
{E5822696-816F-4865-B831-7FE06C42202B}.Release|x86.Build.0 = Release|Any CPU
{FCEBCE71-0EA6-4F25-9BD6-A43A3E016D68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCEBCE71-0EA6-4F25-9BD6-A43A3E016D68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCEBCE71-0EA6-4F25-9BD6-A43A3E016D68}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -200,9 +158,6 @@ Global
{260D8F9B-27F1-4318-908A-0B8A7924D391} = {7AC305D7-5603-4073-8893-5104847367AB}
{F313B95E-6166-4D34-B4B5-E86B44926299} = {7AC305D7-5603-4073-8893-5104847367AB}
{16CBDB12-56E7-4B6C-BDF6-7B55FC35BE27} = {7AC305D7-5603-4073-8893-5104847367AB}
{3CD0F3BC-AC7B-4B49-A8B3-A50A7E8EB886} = {8907097C-8D6C-4F01-8CA3-871C6489171F}
{3C591EBC-7DBF-4FBA-8B0A-E0B966BCC7F7} = {8907097C-8D6C-4F01-8CA3-871C6489171F}
{E5822696-816F-4865-B831-7FE06C42202B} = {8907097C-8D6C-4F01-8CA3-871C6489171F}
{FCEBCE71-0EA6-4F25-9BD6-A43A3E016D68} = {8907097C-8D6C-4F01-8CA3-871C6489171F}
{184B514D-8548-4C6A-9C52-A521051013CD} = {07D37E4D-3609-4732-8BED-7C3F69694CF0}
{94A3288D-4F78-4744-B8B2-135C772DBE26} = {07D37E4D-3609-4732-8BED-7C3F69694CF0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,52 @@ namespace Eurofurence.App.Domain.Model.MongoDb.DependencyResolution
{
public class AutofacModule : Module
{
private readonly IMongoDatabase _mongoDatabase;
private MongoDatabaseInitialization _mongoDatabaseInitialization;

public AutofacModule(IMongoDatabase mongoDatabase)
public AutofacModule()
{
_mongoDatabase = mongoDatabase;
_mongoDatabaseInitialization = new MongoDatabaseInitialization();
}

private void Register<TRepository, IRepository, TRecord>(
ContainerBuilder builder,
Action<IMongoCollection<TRecord>> setup = null
) where TRecord: IEntityBase
{
var name = typeof(TRecord).FullName.Replace("Eurofurence.App.Domain.Model.", "");
var collection = _mongoDatabase.GetCollection<TRecord>(name);
_mongoDatabaseInitialization.InitializationTasks.Add(mongoDatabase =>
{
var name = typeof(TRecord).FullName.Replace("Eurofurence.App.Domain.Model.", "");
var collection = mongoDatabase.GetCollection<TRecord>(name);

builder.Register(r => collection).As<IMongoCollection<TRecord>>();
builder.RegisterType<TRepository>().As<IRepository>();
builder.Register(r => collection).As<IMongoCollection<TRecord>>();
builder.RegisterType<TRepository>().As<IRepository>();


var createBasicIndexes = new Action(() =>
{
collection.Indexes.CreateOne(Builders<TRecord>.IndexKeys.Ascending(a => a.IsDeleted));
collection.Indexes.CreateOne(Builders<TRecord>.IndexKeys.Descending(a => a.LastChangeDateTimeUtc));
});
var createBasicIndexes = new Action(() =>
{
collection.Indexes.CreateOne(Builders<TRecord>.IndexKeys.Ascending(a => a.IsDeleted));
collection.Indexes.CreateOne(Builders<TRecord>.IndexKeys.Descending(a => a.LastChangeDateTimeUtc));
});

try
{
createBasicIndexes();
setup?.Invoke(collection);
}
catch (MongoWriteConcernException)
{
collection.Indexes.DropAll();
createBasicIndexes();
setup?.Invoke(collection);
}
try
{
createBasicIndexes();
setup?.Invoke(collection);
}
catch (MongoWriteConcernException)
{
collection.Indexes.DropAll();
createBasicIndexes();
setup?.Invoke(collection);
}

});
}

protected override void Load(ContainerBuilder builder)
{
builder.RegisterInstance<IMongoDatabaseInitialization>(_mongoDatabaseInitialization);

Register<EntityStorageInfoRepository, IEntityStorageInfoRepository, EntityStorageInfoRecord>(builder);
Register<EventRepository, IEntityRepository<EventRecord>, EventRecord>(builder);
Register<EventConferenceDayRepository, IEntityRepository<EventConferenceDayRecord>, EventConferenceDayRecord>(builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MongoDB.Driver;

namespace Eurofurence.App.Domain.Model.MongoDb.DependencyResolution
{
public interface IMongoDatabaseInitialization
{
void ExecuteInitializationTasks(IMongoDatabase database);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;

namespace Eurofurence.App.Domain.Model.MongoDb.DependencyResolution
{
internal class MongoDatabaseInitialization : IMongoDatabaseInitialization
{
public List<Action<IMongoDatabase>> InitializationTasks { get; }

public MongoDatabaseInitialization()
{
InitializationTasks = new List<Action<IMongoDatabase>>();
}

public void ExecuteInitializationTasks(IMongoDatabase database)
{
InitializationTasks.ForEach(task => task.Invoke(database));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Autofac;
using Eurofurence.App.Server.Services.Abstraction.Telegram;
using Eurofurence.App.Server.Services.Abstractions;
using Eurofurence.App.Server.Services.Abstractions.Announcements;
using Eurofurence.App.Server.Services.Abstractions.ArtistsAlley;
Expand Down Expand Up @@ -29,54 +30,122 @@
using Eurofurence.App.Server.Services.Storage;
using Eurofurence.App.Server.Services.Telegram;
using Eurofurence.App.Server.Services.Validation;
using Microsoft.Extensions.Configuration;
using System;

namespace Eurofurence.App.Server.Services.DependencyResolution
{
public class AutofacModule : Module
{
private readonly IConfiguration _configuration;

public AutofacModule(IConfiguration configuration)
{
_configuration = configuration;
}

protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<StorageServiceFactory>().As<IStorageServiceFactory>();
builder.RegisterType<EventService>().As<IEventService>();
builder.RegisterType<EventConferenceTrackService>().As<IEventConferenceTrackService>();
builder.RegisterType<EventConferenceRoomService>().As<IEventConferenceRoomService>();
builder.RegisterType<EventConferenceDayService>().As<IEventConferenceDayService>();
builder.RegisterType<EventFeedbackService>().As<IEventFeedbackService>();
builder.RegisterType<KnowledgeGroupService>().As<IKnowledgeGroupService>();
builder.RegisterType<KnowledgeEntryService>().As<IKnowledgeEntryService>();
builder.RegisterType<ImageService>().As<IImageService>();
builder.RegisterType<DealerService>().As<IDealerService>();
builder.RegisterType<AnnouncementService>().As<IAnnouncementService>();
builder.RegisterType<MapService>().As<IMapService>();
RegisterConfigurations(builder);
RegisterServices(builder);
}

builder.RegisterType<TokenFactory>().As<ITokenFactory>();
private void RegisterConfigurations(ContainerBuilder builder)
{
if (_configuration == null) return;

builder.RegisterInstance(new ConventionSettings()
{
ConventionIdentifier = _configuration["global:conventionIdentifier"],
IsRegSysAuthenticationEnabled = Convert.ToInt32(_configuration["global:regSysAuthenticationEnabled"]) == 1,
ApiBaseUrl = _configuration["global:apiBaseUrl"]
});

builder.RegisterInstance(new TokenFactorySettings
{
SecretKey = _configuration["oAuth:secretKey"],
Audience = _configuration["oAuth:audience"],
Issuer = _configuration["oAuth:issuer"]
});

builder.RegisterInstance(new AuthenticationSettings
{
DefaultTokenLifeTime = TimeSpan.FromDays(30)
});

builder.RegisterInstance(new WnsConfiguration
{
ClientId = _configuration["wns:clientId"],
ClientSecret = _configuration["wns:clientSecret"],
TargetTopic = _configuration["wns:targetTopic"]
});

builder.RegisterInstance(new FirebaseConfiguration
{
AuthorizationKey = _configuration["firebase:authorizationKey"],
});

builder.RegisterInstance(new TelegramConfiguration
{
AccessToken = _configuration["telegram:accessToken"],
Proxy = _configuration["telegram:proxy"]
});

builder.RegisterInstance(new CollectionGameConfiguration()
{
LogFile = _configuration["collectionGame:logFile"],
LogLevel = Convert.ToInt32(_configuration["collectionGame:logLevel"]),
TelegramManagementChatId = _configuration["collectionGame:telegramManagementChatId"]
});

builder.RegisterInstance(new ArtistAlleyConfiguration()
{
TelegramAdminGroupChatId = _configuration["artistAlley:telegram:adminGroupChatId"],
TelegramAnnouncementChannelId = _configuration["artistAlley:telegram:announcementChannelId"],
TwitterConsumerKey = _configuration["artistAlley:twitter:consumerKey"],
TwitterConsumerSecret = _configuration["artistAlley:twitter:consumerSecret"],
TwitterAccessToken = _configuration["artistAlley:twitter:accessToken"],
TwitterAccessTokenSecret = _configuration["artistAlley:twitter:accessTokenSecret"]
});
}

private void RegisterServices(ContainerBuilder builder)
{
builder.RegisterType<AnnouncementService>().As<IAnnouncementService>();
builder.RegisterType<AuthenticationHandler>().As<IAuthenticationHandler>();
builder.RegisterType<PushNotificiationChannelService>().As<IPushNotificiationChannelService>();
builder.RegisterType<WnsChannelManager>().As<IWnsChannelManager>();
builder.RegisterType<PushEventMediator>().As<IPushEventMediator>();
builder.RegisterType<PushNotificationChannelStatisticsService>().As<IPushNotificationChannelStatisticsService>();
builder.RegisterType<BotManager>().As<BotManager>();
builder.RegisterType<CollectingGameService>().As<ICollectingGameService>();
builder.RegisterType<DealerService>().As<IDealerService>();
builder.RegisterType<EventConferenceDayService>().As<IEventConferenceDayService>();
builder.RegisterType<EventConferenceRoomService>().As<IEventConferenceRoomService>();
builder.RegisterType<EventConferenceTrackService>().As<IEventConferenceTrackService>();
builder.RegisterType<EventFeedbackService>().As<IEventFeedbackService>();
builder.RegisterType<EventService>().As<IEventService>();
builder.RegisterType<FirebaseChannelManager>().As<IFirebaseChannelManager>();
builder.RegisterType<FursuitBadgeService>().As<IFursuitBadgeService>();
builder.RegisterType<ImageService>().As<IImageService>();
builder.RegisterType<ItemActivityService>().As<IItemActivityService>();
builder.RegisterType<KnowledgeEntryService>().As<IKnowledgeEntryService>();
builder.RegisterType<KnowledgeGroupService>().As<IKnowledgeGroupService>();
builder.RegisterType<LinkFragmentValidator>().As<ILinkFragmentValidator>();
builder.RegisterType<MapService>().As<IMapService>();
builder.RegisterType<PrivateMessageService>()
.As<IPrivateMessageService>()
.SingleInstance();

builder.RegisterType<PushEventMediator>().As<IPushEventMediator>();
builder.RegisterType<PushNotificationChannelStatisticsService>().As<IPushNotificationChannelStatisticsService>();
builder.RegisterType<PushNotificiationChannelService>().As<IPushNotificiationChannelService>();
builder.RegisterType<RegSysAlternativePinAuthenticationProvider>()
.As<IRegSysAlternativePinAuthenticationProvider>();

builder.RegisterType<BotManager>().As<BotManager>();
builder.RegisterType<StorageServiceFactory>().As<IStorageServiceFactory>();
builder.RegisterType<TableRegistrationService>().As<ITableRegistrationService>();
builder.RegisterType<TelegramMessageBroker>()
.As<ITelegramMessageBroker>()
.As<ITelegramMessageSender>()
.SingleInstance();

builder.RegisterType<TokenFactory>().As<ITokenFactory>();
builder.RegisterType<UserManager>().As<IUserManager>();


builder.RegisterType<FursuitBadgeService>().As<IFursuitBadgeService>();
builder.RegisterType<CollectingGameService>().As<ICollectingGameService>();
builder.RegisterType<ItemActivityService>().As<IItemActivityService>();
builder.RegisterType<TableRegistrationService>().As<ITableRegistrationService>();
builder.RegisterType<WnsChannelManager>().As<IWnsChannelManager>();
}
}
}
Loading