-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor module behaviour out and into a BaseModule.
- Loading branch information
1 parent
2e0bfac
commit 70b658c
Showing
7 changed files
with
48 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Micro.Users; | ||
|
||
public class BaseModule | ||
{ | ||
private readonly Func<IServiceScope> _scopeFactory; | ||
|
||
protected BaseModule(Func<IServiceScope> scopeFactory) | ||
{ | ||
_scopeFactory = scopeFactory; | ||
} | ||
|
||
public async Task SendCommand(IRequest command) | ||
{ | ||
using var scope = _scopeFactory.Invoke(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Send(command); | ||
} | ||
|
||
public async Task<TResult> SendQuery<TResult>(IRequest<TResult> query) | ||
{ | ||
using var scope = _scopeFactory.Invoke(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
return await dispatcher.Send(query); | ||
} | ||
|
||
public async Task PublishNotification(INotification notification) | ||
{ | ||
using var scope = _scopeFactory.Invoke(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Publish(notification); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
using Micro.Tenants.Infrastructure; | ||
using Micro.Common; | ||
using Micro.Tenants.Infrastructure; | ||
using Micro.Users; | ||
|
||
namespace Micro.Tenants; | ||
|
||
public class TenantsModule : ITenantsModule | ||
{ | ||
public async Task SendCommand(IRequest command) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Send(command); | ||
} | ||
public interface ITenantsModule : IModule; | ||
|
||
public async Task<TResult> SendQuery<TResult>(IRequest<TResult> query) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
return await dispatcher.Send(query); | ||
} | ||
|
||
public async Task PublishNotification(INotification notification) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Publish(notification); | ||
} | ||
} | ||
public class TenantsModule() : BaseModule(CompositionRoot.BeginLifetimeScope), ITenantsModule; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
using Micro.Translations.Infrastructure; | ||
using Micro.Common; | ||
using Micro.Translations.Infrastructure; | ||
using Micro.Users; | ||
|
||
namespace Micro.Translations; | ||
|
||
public class TranslationModule : ITranslationModule | ||
{ | ||
public async Task SendCommand(IRequest command) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Send(command); | ||
} | ||
public interface ITranslationModule : IModule; | ||
|
||
public async Task<TResult> SendQuery<TResult>(IRequest<TResult> query) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
return await dispatcher.Send(query); | ||
} | ||
|
||
public async Task PublishNotification(INotification notification) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Publish(notification); | ||
} | ||
} | ||
public class TranslationModule() : BaseModule(CompositionRoot.BeginLifetimeScope), ITranslationModule; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,8 @@ | ||
using Micro.Users.Infrastructure; | ||
using Micro.Common; | ||
using Micro.Users.Infrastructure; | ||
|
||
namespace Micro.Users; | ||
|
||
public class UsersModule : IUsersModule | ||
{ | ||
public async Task SendCommand(IRequest command) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Send(command); | ||
} | ||
public interface IUsersModule : IModule; | ||
|
||
public async Task<TResult> SendQuery<TResult>(IRequest<TResult> query) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
return await dispatcher.Send(query); | ||
} | ||
|
||
public async Task PublishNotification(INotification notification) | ||
{ | ||
using var scope = CompositionRoot.BeginLifetimeScope(); | ||
var dispatcher = scope.ServiceProvider.GetRequiredService<IMediator>(); | ||
await dispatcher.Publish(notification); | ||
} | ||
} | ||
public class UsersModule() : BaseModule(CompositionRoot.BeginLifetimeScope), IUsersModule; |