-
-
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.
merged OaktonOptions into JasperFx options
- Loading branch information
1 parent
acbebe8
commit f257b9a
Showing
6 changed files
with
75 additions
and
70 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 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
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,49 @@ | ||
using System.Reflection; | ||
using JasperFx.CommandLine; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace JasperFx; | ||
|
||
public static class JasperFxServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Configure JasperFx and Critter Stack tool behavior for resource management at runtime | ||
/// </summary> | ||
/// <param name="services"></param> | ||
/// <param name="configure">Optional configuration of the JasperFxDefaults for resource management</param> | ||
/// <returns></returns> | ||
public static IServiceCollection AddJasperFx(this IServiceCollection services, Action<JasperFxOptions>? configure = null) | ||
{ | ||
var optionsBuilder = services.AddOptions<JasperFxOptions>(); | ||
if (configure != null) | ||
{ | ||
optionsBuilder.Configure(configure!); | ||
} | ||
|
||
optionsBuilder.PostConfigure<IHostEnvironment>((o, e) => o.ReadHostEnvironment(e)); | ||
services.AddSingleton<JasperFxOptions>(s => | ||
{ | ||
return s.GetRequiredService<IOptions<JasperFxOptions>>().Value; | ||
}); | ||
|
||
services.TryAddScoped<ICommandCreator, DependencyInjectionCommandCreator>(); | ||
|
||
services.TryAddScoped<ICommandFactory>(ctx => | ||
{ | ||
var creator = ctx.GetRequiredService<ICommandCreator>(); | ||
var oaktonOptions = ctx.GetRequiredService<IOptions<JasperFxOptions>>().Value; | ||
|
||
var factory = new CommandFactory(creator); | ||
factory.ApplyFactoryDefaults(Assembly.GetEntryAssembly()); | ||
oaktonOptions.Factory?.Invoke(factory); | ||
return factory; | ||
}); | ||
|
||
services.TryAddScoped<CommandExecutor>(); | ||
|
||
return services; | ||
} | ||
} |