1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-23 14:45:37 +01:00
GiantsTools/Giants.Services/Core/ServicesModule.cs

76 lines
2.7 KiB
C#
Raw Normal View History

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;
using Giants.Services.Store;
2022-09-09 07:31:24 +02:00
using Giants.Services.Utility;
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;
2022-09-09 07:31:24 +02:00
public class ServicesModule : Module
{
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)
{
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 =>
{
2022-09-09 07:31:24 +02:00
var versionStore = icc.Resolve<IVersioningStore>();
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();
}
}
}