-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add configurator for better extension control
- Loading branch information
Showing
9 changed files
with
73 additions
and
14 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
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
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
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
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,45 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Shiny.Mediator; | ||
|
||
|
||
public sealed class ShinyConfigurator(IServiceCollection services) | ||
{ | ||
public ShinyConfigurator AddRequestMiddleware<TRequest, TResult, TImpl>( | ||
ServiceLifetime lifetime = ServiceLifetime.Scoped) | ||
where TRequest : IRequest<TResult> | ||
where TImpl : class, IRequestMiddleware<TRequest, TResult> | ||
{ | ||
switch (lifetime) | ||
{ | ||
case ServiceLifetime.Transient: | ||
services.AddTransient<IRequestMiddleware<TRequest, TResult>, TImpl>(); | ||
break; | ||
|
||
case ServiceLifetime.Scoped: | ||
services.AddScoped<IRequestMiddleware<TRequest, TResult>, TImpl>(); | ||
break; | ||
|
||
case ServiceLifetime.Singleton: | ||
services.AddSingleton<IRequestMiddleware<TRequest, TResult>, TImpl>(); | ||
break; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
|
||
public ShinyConfigurator AddOpenRequestMiddleware(Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Scoped) | ||
{ | ||
// validate open generic | ||
services.Add(new ServiceDescriptor(typeof(IRequestMiddleware<,>), null, implementationType, lifetime)); | ||
return this; | ||
} | ||
|
||
|
||
public ShinyConfigurator AddEventCollector<TImpl>() where TImpl : class, IEventCollector | ||
{ | ||
services.AddSingleton<IEventCollector, TImpl>(); | ||
return this; | ||
} | ||
} |
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
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
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
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