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 Service Collection Extensions to all Clients #45

Merged
merged 1 commit into from
Jun 30, 2020
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 @@ -21,6 +21,9 @@ public static IServiceCollection AddEventStoreOperationsClient(this IServiceColl

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ReSharper disable CheckNamespace

using System;
using System.Net.Http;
using EventStore.Client;
using Grpc.Core.Interceptors;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

#nullable enable
namespace Microsoft.Extensions.DependencyInjection {
public static class EventStorePersistentSubscriptionsClientCollectionExtensions {
public static IServiceCollection AddEventStorePersistentSubscriptionsClient(this IServiceCollection services, Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
=> services.AddEventStorePersistentSubscriptionsClient(options => {
options.ConnectivitySettings.Address = address;
options.CreateHttpMessageHandler = createHttpMessageHandler;
});

public static IServiceCollection AddEventStorePersistentSubscriptionsClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) {
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>();

return new EventStorePersistentSubscriptionsClient(settings);
});

return services;
}
}
}
// ReSharper restore CheckNamespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ReSharper disable CheckNamespace

using System;
using System.Net.Http;
using EventStore.Client;
using Grpc.Core.Interceptors;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

#nullable enable
namespace Microsoft.Extensions.DependencyInjection {
public static class EventStoreProjectionManagementClientCollectionExtensions {
public static IServiceCollection AddEventStoreProjectionManagementClient(this IServiceCollection services, Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
=> services.AddEventStoreProjectionManagementClient(options => {
options.ConnectivitySettings.Address = address;
options.CreateHttpMessageHandler = createHttpMessageHandler;
});

public static IServiceCollection AddEventStoreProjectionManagementClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) {
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>();

return new EventStoreProjectionManagementClient(settings);
});

return services;
}
}
}
// ReSharper restore CheckNamespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ReSharper disable CheckNamespace

using System;
using System.Net.Http;
using EventStore.Client;
using Grpc.Core.Interceptors;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

#nullable enable
namespace Microsoft.Extensions.DependencyInjection {
public static class EventStoreUserManagementClientCollectionExtensions {
public static IServiceCollection AddEventStoreUserManagementClient(this IServiceCollection services, Uri address,
Func<HttpMessageHandler>? createHttpMessageHandler = null)
=> services.AddEventStoreUserManagementClient(options => {
options.ConnectivitySettings.Address = address;
options.CreateHttpMessageHandler = createHttpMessageHandler;
});

public static IServiceCollection AddEventStoreUserManagementClient(this IServiceCollection services,
Action<EventStoreClientSettings>? configureSettings = null) {
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>();

return new EventStoreUserManagementClient(settings);
});

return services;
}
}
}
// ReSharper restore CheckNamespace