Skip to content

Commit

Permalink
Pass InstrumentationOptions in AddMongoDbContext<TContext>(...) ove…
Browse files Browse the repository at this point in the history
…rloads that take connection strings (#261)
  • Loading branch information
mburumaxwell authored May 22, 2024
1 parent f15fd73 commit 8140066
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using MongoDB.Driver;
using MongoDB.Driver.Core.Extensions.DiagnosticSources;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Tingle.Extensions.MongoDB;
Expand Down Expand Up @@ -32,27 +33,29 @@ public static IServiceCollection AddMongoDatabaseSetup<TContext>(this IServiceCo
this IServiceCollection services,
IConfiguration configuration,
Action<MongoDbContextOptionsBuilder>? optionsAction = null,
InstrumentationOptions? instrumentationOptions = null,
ServiceLifetime contextLifetime = ServiceLifetime.Singleton,
ServiceLifetime optionsLifetime = ServiceLifetime.Singleton)
where TContext : MongoDbContext
{
var connectionString = configuration.GetConnectionString("Mongo");
return connectionString is not null
? AddMongoDbContext<TContext>(services, connectionString: connectionString, optionsAction, contextLifetime, optionsLifetime)
? AddMongoDbContext<TContext>(services, connectionString: connectionString, optionsAction, instrumentationOptions, contextLifetime, optionsLifetime)
: AddMongoDbContext<TContext>(services, optionsAction, contextLifetime, optionsLifetime);
}

public static IServiceCollection AddMongoDbContext<[DynamicallyAccessedMembers(MongoDbContext.DynamicallyAccessedMemberTypes)] TContext>(
this IServiceCollection services,
string connectionString,
Action<MongoDbContextOptionsBuilder>? optionsAction = null,
InstrumentationOptions? instrumentationOptions = null,
ServiceLifetime contextLifetime = ServiceLifetime.Singleton,
ServiceLifetime optionsLifetime = ServiceLifetime.Singleton)
where TContext : MongoDbContext
{
return AddMongoDbContext<TContext>(services, options =>
{
options.UseMongoConnectionString(connectionString);
options.UseMongoConnectionString(connectionString, instrumentationOptions);
optionsAction?.Invoke(options);
}, contextLifetime, optionsLifetime);
}
Expand Down

0 comments on commit 8140066

Please sign in to comment.