2020-08-08 08:53:35 +02:00
|
|
|
|
namespace Giants.Services
|
|
|
|
|
{
|
2022-09-09 07:31:24 +02:00
|
|
|
|
using Autofac;
|
2020-08-09 01:31:16 +02:00
|
|
|
|
using Giants.Services.Core;
|
2020-08-16 11:03:10 +02:00
|
|
|
|
using Giants.Services.Services;
|
2020-08-10 09:22:33 +02:00
|
|
|
|
using Giants.Services.Store;
|
2022-09-09 07:31:24 +02:00
|
|
|
|
using Giants.Services.Utility;
|
2020-08-09 11:10:33 +02:00
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
2020-08-09 01:31:16 +02:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2022-09-09 07:31:24 +02:00
|
|
|
|
using System;
|
2020-08-08 08:53:35 +02:00
|
|
|
|
|
2022-09-09 07:31:24 +02:00
|
|
|
|
public class ServicesModule : Module
|
2020-08-08 08:53:35 +02:00
|
|
|
|
{
|
2022-09-09 07:31:24 +02:00
|
|
|
|
private readonly IConfiguration configuration;
|
|
|
|
|
|
|
|
|
|
public ServicesModule(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
this.configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
2020-08-08 08:53:35 +02:00
|
|
|
|
{
|
2022-09-09 07:31:24 +02:00
|
|
|
|
builder.RegisterType<ServerRegistryService>()
|
|
|
|
|
.As<IServerRegistryService>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
builder.RegisterType<CosmosDbServerRegistryStore>()
|
|
|
|
|
.As<IServerRegistryStore>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
builder.RegisterType<DefaultDateTimeProvider>()
|
|
|
|
|
.As<IDateTimeProvider>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
builder.RegisterType<MemoryCache>()
|
|
|
|
|
.As<IMemoryCache>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
builder.RegisterType<CosmosDbVersioningStore>()
|
|
|
|
|
.As<IVersioningStore>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
builder.RegisterType<VersioningService>()
|
|
|
|
|
.As<IVersioningService>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
builder.RegisterType<CommunityService>()
|
|
|
|
|
.As<ICommunityService>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
builder.RegisterType<CrashReportService>()
|
|
|
|
|
.As<ICrashReportService>()
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
|
|
|
|
|
var cosmosClient = new CosmosDbClient(
|
|
|
|
|
connectionString: this.configuration["CosmosDbEndpoint"],
|
|
|
|
|
authKeyOrResourceToken: this.configuration["CosmosDbKey"],
|
|
|
|
|
databaseId: this.configuration["DatabaseId"],
|
|
|
|
|
containerId: this.configuration["ContainerId"]);
|
|
|
|
|
|
|
|
|
|
cosmosClient.Initialize().GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
builder.RegisterInstance(cosmosClient).SingleInstance();
|
|
|
|
|
|
|
|
|
|
builder.Register<ISimpleMemoryCache<VersionInfo>>(icc =>
|
2020-09-01 20:04:22 +02:00
|
|
|
|
{
|
2022-09-09 07:31:24 +02:00
|
|
|
|
var versionStore = icc.Resolve<IVersioningStore>();
|
2020-09-01 20:04:22 +02:00
|
|
|
|
|
2022-09-09 07:31:24 +02:00
|
|
|
|
return new SimpleMemoryCache<VersionInfo>(
|
|
|
|
|
expirationPeriod: TimeSpan.FromMinutes(5),
|
|
|
|
|
memoryCache: icc.Resolve<IMemoryCache>(),
|
|
|
|
|
cacheKey: CacheKeys.VersionInfo,
|
|
|
|
|
getAllItems: async (cacheEntry) =>
|
|
|
|
|
{
|
|
|
|
|
return await versionStore.GetVersions();
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.AsSelf()
|
|
|
|
|
.SingleInstance();
|
2020-08-08 08:53:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|