In ASP.NET Core 2 application I set up some services:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(o
Dependency injection is possible in asp.net core razor pages as well.
You can do constructor injection in your page model class.
public class LoginModel : PageModel
{
private IFileSystem fileSystem;
public LoginModel(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
}
[BindProperty]
public string EmailAddress { get; set; }
public async Task OnPostRefresh()
{
// now you can use this.fileSystem
//to do : return something
}
}
Dependency injection is also possible in the pages :). Simply use the inject
directive.
@model YourNameSpace.LoginModel
@inject IFileSystem FileSystem;
My page
// Use FileSystem now