Unable to resolve options in startup.cs with non core project

207 views Asked by At

I have asp net webapi and i'm need resolve some options in startup file. Option here has simple class what take parameters from json configuration. In startup registering the optionsAutofacModule where register configuration section what i'm need. Example: RegisterConfigurationOptions<IdentitySettings>(builder, configuration.GetSection("Identity")); in OptionAutofacModule, whitch the containerBuilder.RegisterModule<OptionsAutofacModule>();, which called in startup .cs. So, i'm need access to "identitysettings" inside method in startup.cs.

Edit 0: I have net core project and classic asp net web api. Net core project using configuration, what resolving from json file. I can access to this configuration inside controllers classical .net webapi project, using IOptions. But i can't access to this options inside startup.cs

1

There are 1 answers

0
QuaternioNoir On BEST ANSWER

In theory, the solution is simple, but I forgot about beginscope. Solution:

config.DependencyResolver
      .BeginScope()
      .GetService(typeof(IOptions<YourOptions>)) as IOptions<YourOptions>;

where config is HttpConfiguration