private ServiceProvider CreateContainer(IOption option) { var container = new ServiceCollection(); container.AddHttpClient(); container.AddLogging(config => { config .AddConsole() .AddDebug(); if (!option.LogFolder.IsEmpty()) { config.AddFileLogger(option.LogFolder !, "PathFinder"); } }); container.AddSingleton(option); container.AddSingleton <IJson, Json>(); container.AddSingleton <TemplateActivity>(); if (option.Store != null) { container.AddSingleton <ICosmosPathFinderOption>(option.Store); container.AddSingleton <IPathFinderStore, CosmosPathFinderStore>(); container.AddSingleton <IRecordContainer <LinkRecord> >(services => { IPathFinderStore store = services.GetRequiredService <IPathFinderStore>(); return(store.Container.Get <LinkRecord>()); }); container.AddSingleton <IRecordContainer <MetadataRecord> >(services => { IPathFinderStore store = services.GetRequiredService <IPathFinderStore>(); return(store.Container.Get <MetadataRecord>()); }); container.AddSingleton <LinkActivity>(); container.AddSingleton <MetadataActivity>(); container.AddSingleton <ImportActivity>(); } return(container.BuildServiceProvider()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSingleton <IPathFinderStore, CosmosPathFinderStore>(); services.AddSingleton <ITelemetryMemory, TelemetryMemory>(); // Register path services actor host (bind DI to actor) services.AddPathServiceActorHost(); // Register path services (link & metadata) services.AddPathServices(); services.AddSingleton <IRecordContainer <LinkRecord> >(services => { IPathFinderStore store = services.GetRequiredService <IPathFinderStore>(); return(store.Container.Get <LinkRecord>()); }); services.AddSingleton <IRecordContainer <MetadataRecord> >(services => { IPathFinderStore store = services.GetRequiredService <IPathFinderStore>(); return(store.Container.Get <MetadataRecord>()); }); services.AddSwaggerDocument(config => { config.PostProcess = document => { document.Info.Title = "Path Finder - Links and Metadata"; document.Info.Description = "API Server for Path Finder services"; document.Schemes = new[] { OpenApiSchema.Http | OpenApiSchema.Https }; }; }); services.AddCors(x => x.AddPolicy(_policyName, builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .SetPreflightMaxAge(TimeSpan.FromHours(1)); })); }