Я настроил NamedOption
в ConfigureServices
метод Startup.cs
, как показано ниже:
services.Configure<MyOpts>("myOpts",
opts => configuration.Bind("myOpts", opts));
У меня есть действие контроллера в asp.net core
API, например:
public async Task<IActionResult> Insert(CreateUserCommand command)
{
var id = await Mediator.Send(command);
return Ok(id);
}
Это мой CreateUserCommand
:
public class CreateUserCommand
{
private MyOpts opts { get; }
public CreateUserCommand(IOptionsSnapshot<MyOpts> opts)
{
this.opts = opts.Get("myOpts");
}
public long UserId { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
}
Когда клиент нажимает мой API, я хочу, чтобы MyOpts
объект вводился в CreateUserCommand(IOptionsSnapshot<MyOpts> opts)
. CreateUserCommand находится в сборке, отличной от asp. net основного проекта. Можно ли добиться такого поведения?