Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Connection String Overloads for DI Extensions #83

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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