// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //var mongoDbStore = new MongoDbPacketsStore(new MongoDbParameters("mongodb://localhost:5555", TransportConstants.MongoDatabaseName)); //MongoDbClusterPacketsStoreUtils.CreateMongoClusterPacketsStore(new DbClusterReservateSettings()); var mongoUrls = new string[] { //"mongodb://localhost:5555", "mongodb://localhost:3333", }; var clusterParams = new DbClusterServiceParameters(mongoUrls, TransportConstants.MongoDatabaseName); var reservationParams = new DbClusterReservationsSettings(TimeSpan.FromSeconds(3)); services.AddMongoServices(new AssignedUnitIdProvider("dhu2"), new MongoServicesOptions(clusterParams, reservationParams)); services.AddSingleton <IHostedService, DbClusterServiceHostObjectWrapper>(); services.AddSingleton <IPacketsStore, DbClusterPacketsStore>(ctx => new DbClusterPacketsStore(ctx.GetRequiredService <IDbClusterService>(), dbParameters => new MongoDbPacketsStore(new MongoDbParameters(dbParameters.ConnStringOrUrl, dbParameters.DatabaseName)))); services.AddSingleton <ITransportRequestService, HttpMessageRequestParser>(); var agentConfigurationsHandler = new AgentConfigurationsService(); agentConfigurationsHandler.AddWithKeyOrThrow(new TestAgentDynamicConfigurationProvider()); var queueManager = new LimitConcurrentQueueManager(50, TimeSpan.FromSeconds(36)); services.AddSingleton <IThrottleQueueManager>(queueManager); services.AddSingleton <IAgentStaticConfigService, AgentStaticConfigService>(); services.AddSingleton <IDbTokenService, DbTokenService>(); services.AddSingleton <IAgentConfigurationsService>(agentConfigurationsHandler); services.AddMvc() // .AddApplicationPart(typeof(TransportController).Assembly) .AddControllersAsServices(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var mongoUrls = new string[] { "mongodb://192.168.100.184:27017", // "mongodb://localhost:3333", }; var clusterParams = new DbClusterServiceParameters(mongoUrls, TransportConstants.MongoDatabaseName, TransportConstants.DefaultLeaseCheckTimeout, TransportConstants.DefaultLeaseLostTimeout, TransportConstants.DefaultUpdateServerTimeInterval); var reservationParams = new DbClusterReservationsSettings(TimeSpan.FromSeconds(3)); services.AddMongoServices(new ComputerNameUnitIdProvider(TimeSpan.FromMinutes(30)), new MongoServicesOptions(clusterParams, reservationParams)); services.AddSingleton <IHostedService, DbClusterServiceHostObjectWrapper>(); services.AddSingleton <IPacketsStore, DbClusterPacketsStore>(ctx => new DbClusterPacketsStore(ctx.GetRequiredService <IDbClusterService>(), dbParameters => new MongoDbPacketsStore(new MongoDbParameters(dbParameters.ConnStringOrUrl, dbParameters.DatabaseName)))); services.AddSingleton <ITransportRequestService, HttpMessageRequestParser>(); var agentConfigurationsHandler = new AgentConfigurationsService(); agentConfigurationsHandler.AddWithKeyOrThrow(new TestAgentDynamicConfigurationProvider()); var queueManager = new LimitConcurrentQueueManager(3, TimeSpan.FromSeconds(36)); services.AddSingleton <IThrottleQueueManager>(queueManager); services.AddSingleton <IAgentStaticConfigService, AgentStaticConfigService>(); services.AddSingleton <IDbTokenService, DbTokenService>(); services.AddSingleton <IAgentConfigurationsService>(agentConfigurationsHandler); services.AddMvcCore().AddFormatterMappings() .AddJsonFormatters() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }) .AddMvcOptions(options => { var formatter = options.InputFormatters.OfType <JsonInputFormatter>().First(); formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue(MediaTypeNames.Text.Html)); formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue(MediaTypeNames.Application.Octet)); }) // .AddApplicationPart(typeof(TransportController).Assembly) .AddControllersAsServices(); }