namespace Giants.Services { using Autofac; using Giants.Services.Core; using Giants.Services.Services; using Giants.Services.Store; using Giants.Services.Utility; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using System; public class ServicesModule : Module { private readonly IConfiguration configuration; public ServicesModule(IConfiguration configuration) { this.configuration = configuration; } protected override void Load(ContainerBuilder builder) { builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .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>(icc => { var versionStore = icc.Resolve(); return new SimpleMemoryCache( expirationPeriod: TimeSpan.FromMinutes(5), memoryCache: icc.Resolve(), cacheKey: CacheKeys.VersionInfo, getAllItems: async (cacheEntry) => { return await versionStore.GetVersions(); }); }) .AsSelf() .SingleInstance(); } } }