/// <summary> /// Add an IMongoClient instance configured with the given settings /// </summary> /// <param name="services">The services container</param> /// <param name="clientSettings">The mongo client settings to use</param> /// <param name="settings">The telemetry settings to use</param> /// <returns>The services container</returns> public static IServiceCollection AddMongoClient( this IServiceCollection services, MongoClientSettings clientSettings, MongoApplicationInsightsSettings settings = null ) => services .AddMongoClientFactory(settings) .AddSingleton(sp => GetFactory(sp).GetClient(clientSettings));
/// <summary> /// Add an IMongoClientFactory instance configured with the given settings /// </summary> /// <param name="services">The services container</param> /// <param name="settings">The telemetry settings to use</param> /// <returns>The services container</returns> public static IServiceCollection AddMongoClientFactory( this IServiceCollection services, MongoApplicationInsightsSettings settings = null ) => services .AddSingleton(settings ?? new MongoApplicationInsightsSettings()) .AddSingleton <IMongoClientFactory>(sp => new MongoClientFactory( sp.GetService <TelemetryClient>(), sp.GetRequiredService <MongoApplicationInsightsSettings>() ));
/// <summary> /// Add an IMongoClient instance configured with the given settings /// </summary> /// <param name="services">The services container</param> /// <param name="url">The connection string to use</param> /// <param name="settings">The telemetry settings to use</param> /// <returns>The services container</returns> public static IServiceCollection AddMongoClient( this IServiceCollection services, MongoUrl url, MongoApplicationInsightsSettings settings = null ) { return(services .AddMongoClientFactory(settings) .AddSingleton(sp => GetFactory(sp).GetClient(url))); }
public void ConstructorWithSettings() { var stub = new StubTelemetry(); var settings = new MongoApplicationInsightsSettings { FilteredCommands = new HashSet <string>(), MaxQueryTime = TimeSpan.FromDays(6) }; var factory = new MongoClientFactory(stub.TelemetryClient, settings); factory.Settings.Should().BeEquivalentTo(settings); }
public Mocks(bool createTelemetry = true, MongoApplicationInsightsSettings settings = null) { StubTelemetry = new StubTelemetry(); if (createTelemetry) { var mongoClientSettings = MongoClientSettings.FromConnectionString( "mongodb://localhost:27017/"); Telemetry = new MongoApplicationInsightsTelemetry( mongoClientSettings, TelemetryClient, settings ?? new MongoApplicationInsightsSettings()); } }
public void AddMongoClientFactoryWithSettings() { var services = CreateServices(); var settings = new MongoApplicationInsightsSettings { MaxQueryTime = TimeSpan.FromMinutes(10), FilteredCommands = new HashSet <string>() }; services.AddMongoClientFactory(settings); var sp = services.BuildServiceProvider(); var factory = sp.GetRequiredService <IMongoClientFactory>(); factory.Settings.Should().BeEquivalentTo(settings); }