我有继承基类的不同类。基类实现接口 IHealthCheck。每个类都有一个构造函数,根据类需要一个记录器和参数。例如 :
public ConnectionHealthCheck(ILogger logger, string address)
: base(logger)
{
Address = address;
}
Run Code Online (Sandbox Code Playgroud)
我有一个 appSettings.json,它允许我配置多个诊断以在我的健康检查服务中执行。
我在 App.xaml.cs 中获得了诊断列表,我正在尝试将它们添加到 HealthCheck 列表中。
问题是我不能用它旁边的参数进行依赖注入,我不知道什么是最好的解决方案......
这是我的代码的一些部分。
OnStartup 方法:
protected override void OnStartup(StartupEventArgs e)
{
var a = Assembly.GetExecutingAssembly();
using var stream = a.GetManifestResourceStream("appsettings.json");
Configuration = new ConfigurationBuilder()
.AddJsonStream(stream)
.Build();
var host = new HostBuilder()
.ConfigureHostConfiguration(c => c.AddConfiguration(Configuration))
.ConfigureServices(ConfigureServices)
.ConfigureLogging(ConfigureLogging)
.Build();
[...] }
Run Code Online (Sandbox Code Playgroud)
configureService 方法:
private void ConfigureServices(IServiceCollection serviceCollection)
{
// create and add the healthCheck for each diag in the appSettings file …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ASP.NET Core Identity 2.0在我现有的应用程序中设置身份验证.当我使用自己的数据库模式和类时,我有自己的User类,我不得不创建自定义UserStore和自定义UserManager.
所以我在AccountController中有我的登录功能:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return RedirectToLocal(returnUrl);
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToAction(nameof(Lockout));
}
else
{
ModelState.AddModelError(string.Empty, "Connection failed.");
return View(model); …Run Code Online (Sandbox Code Playgroud)