Skip to content

Commit

Permalink
add connection string overloads for di extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
thefringeninja committed Oct 27, 2020
1 parent 2730403 commit bab84a4
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class EventStoreOperationsClientServiceCollectionExtensions {
/// <param name="address"></param>
/// <param name="createHttpMessageHandler"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreOperationsClient(this IServiceCollection services, Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
=> services.AddEventStoreOperationsClient(options => {
Expand All @@ -37,12 +38,27 @@ public static IServiceCollection AddEventStoreOperationsClient(this IServiceColl
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreOperationsClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureOptions = null) {
Action<EventStoreClientSettings>? configureOptions = null) =>
services.AddEventStoreOperationsClient(new EventStoreClientSettings(), configureOptions);

/// <summary>
/// Adds an <see cref="EventStoreOperationsClient"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"></param>
/// <param name="connectionString"></param>
/// <param name="configureOptions"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreOperationsClient(this IServiceCollection services,
string connectionString, Action<EventStoreClientSettings>? configureOptions = null) =>
services.AddEventStoreOperationsClient(EventStoreClientSettings.Create(connectionString), configureOptions);

private static IServiceCollection AddEventStoreOperationsClient(this IServiceCollection services,
EventStoreClientSettings options, Action<EventStoreClientSettings>? configureOptions) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}

var options = new EventStoreClientSettings();
configureOptions?.Invoke(options);

services.TryAddSingleton(provider => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class EventStorePersistentSubscriptionsClientCollectionExtensions
/// <param name="address"></param>
/// <param name="createHttpMessageHandler"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStorePersistentSubscriptionsClient(this IServiceCollection services,
Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
Expand All @@ -36,12 +37,29 @@ public static IServiceCollection AddEventStorePersistentSubscriptionsClient(this
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStorePersistentSubscriptionsClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) {
Action<EventStoreClientSettings>? configureSettings = null) =>
services.AddEventStorePersistentSubscriptionsClient(new EventStoreClientSettings(),
configureSettings);

/// <summary>
/// Adds an <see cref="EventStorePersistentSubscriptionsClient"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"></param>
/// <param name="connectionString"></param>
/// <param name="configureSettings"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStorePersistentSubscriptionsClient(this IServiceCollection services,
string connectionString, Action<EventStoreClientSettings>? configureSettings = null) =>
services.AddEventStorePersistentSubscriptionsClient(EventStoreClientSettings.Create(connectionString),
configureSettings);

private static IServiceCollection AddEventStorePersistentSubscriptionsClient(this IServiceCollection services,
EventStoreClientSettings settings, Action<EventStoreClientSettings>? configureSettings) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}

var settings = new EventStoreClientSettings();
configureSettings?.Invoke(settings);

services.TryAddSingleton(provider => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class EventStoreProjectionManagementClientCollectionExtensions {
/// <param name="address"></param>
/// <param name="createHttpMessageHandler"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreProjectionManagementClient(this IServiceCollection services,
Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
Expand All @@ -36,12 +37,28 @@ public static IServiceCollection AddEventStoreProjectionManagementClient(this IS
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreProjectionManagementClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) {
Action<EventStoreClientSettings>? configureSettings = null) =>
services.AddEventStoreProjectionManagementClient(new EventStoreClientSettings(), configureSettings);

/// <summary>
/// Adds an <see cref="EventStoreProjectionManagementClient"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"></param>
/// <param name="connectionString"></param>
/// <param name="configureSettings"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreProjectionManagementClient(this IServiceCollection services,
string connectionString, Action<EventStoreClientSettings>? configureSettings = null) =>
services.AddEventStoreProjectionManagementClient(EventStoreClientSettings.Create(connectionString),
configureSettings);

private static IServiceCollection AddEventStoreProjectionManagementClient(this IServiceCollection services,
EventStoreClientSettings settings, Action<EventStoreClientSettings>? configureSettings) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}

var settings = new EventStoreClientSettings();
configureSettings?.Invoke(settings);

services.TryAddSingleton(provider => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class EventStoreClientServiceCollectionExtensions {
/// <param name="address"></param>
/// <param name="createHttpMessageHandler"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreClient(this IServiceCollection services, Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
=> services.AddEventStoreClient(options => {
Expand All @@ -36,12 +37,31 @@ public static IServiceCollection AddEventStoreClient(this IServiceCollection ser
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) {
Action<EventStoreClientSettings>? configureSettings = null) =>
services.AddEventStoreClient(new EventStoreClientSettings(), configureSettings);


/// <summary>
/// Adds an <see cref="EventStoreClient"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"></param>
/// <param name="connectionString"></param>
/// <param name="configureSettings"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreClient(this IServiceCollection services,
string connectionString, Action<EventStoreClientSettings>? configureSettings = null) {
if (services == null) {
throw new ArgumentNullException(nameof(services));
}

var settings = new EventStoreClientSettings();
return services.AddEventStoreClient(EventStoreClientSettings.Create(connectionString), configureSettings);
}


private static IServiceCollection AddEventStoreClient(this IServiceCollection services,
EventStoreClientSettings settings,
Action<EventStoreClientSettings>? configureSettings) {
configureSettings?.Invoke(settings);

services.TryAddSingleton(provider => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static class EventStoreUserManagementClientCollectionExtensions {
/// <param name="address"></param>
/// <param name="createHttpMessageHandler"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreUserManagementClient(this IServiceCollection services,
Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
Uri address, Func<HttpMessageHandler>? createHttpMessageHandler = null)
=> services.AddEventStoreUserManagementClient(options => {
options.ConnectivitySettings.Address = address;
options.CreateHttpMessageHandler = createHttpMessageHandler;
Expand All @@ -32,18 +32,34 @@ public static IServiceCollection AddEventStoreUserManagementClient(this IService
/// Adds an <see cref="EventStoreUserManagementClient"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"></param>
/// <param name="connectionString"></param>
/// <param name="configureSettings"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreUserManagementClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) {
string connectionString, Action<EventStoreClientSettings>? configureSettings = null)
=> services.AddEventStoreUserManagementClient(EventStoreClientSettings.Create(connectionString),
configureSettings);


/// <summary>
/// Adds an <see cref="EventStoreUserManagementClient"/> to the <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"></param>
/// <param name="configureSettings"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddEventStoreUserManagementClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) =>
services.AddEventStoreUserManagementClient(new EventStoreClientSettings(), configureSettings);

private static IServiceCollection AddEventStoreUserManagementClient(this IServiceCollection services,
EventStoreClientSettings settings, Action<EventStoreClientSettings>? configureSettings = null) {
configureSettings?.Invoke(settings);
if (services == null) {
throw new ArgumentNullException(nameof(services));
}

var settings = new EventStoreClientSettings();
configureSettings?.Invoke(settings);

services.TryAddSingleton(provider => {
settings.LoggerFactory ??= provider.GetService<ILoggerFactory>();
settings.Interceptors ??= provider.GetServices<Interceptor>();
Expand Down

0 comments on commit bab84a4

Please sign in to comment.