Skip to content

Instantly share code, notes, and snippets.

@dmitry-zaets
Created May 17, 2017 11:32
Show Gist options
  • Save dmitry-zaets/c3e5c9482e6df42cccc4828df392ad6a to your computer and use it in GitHub Desktop.
Save dmitry-zaets/c3e5c9482e6df42cccc4828df392ad6a to your computer and use it in GitHub Desktop.
public static void RegisterConfigurationOptions<TOptions>(this ContainerBuilder builder, IConfiguration config) where TOptions : class
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
builder.RegisterInstance(new ConfigurationChangeTokenSource<TOptions>(config))
.As<IOptionsChangeTokenSource<TOptions>>()
.SingleInstance();
builder.RegisterInstance(new ConfigureFromConfigurationOptions<TOptions>(config))
.As<IConfigureOptions<TOptions>>()
.SingleInstance();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment