-
Notifications
You must be signed in to change notification settings - Fork 258
ASP.NET MVC Core integration
John Zabroski edited this page Nov 25, 2020
·
5 revisions
(!) This topic is for RazorLight 1.x. It does not apply to RazorLight 2.y
RazorLight.MVC package enables you to use @inject directive to inject services to your templates from ASP.NET MVC Core IOC container
-
Add package
Install-Package RazorLight.MVC
-
Add RazorLight services in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
....
services.AddRazorLight("/Views"); // <- This one
....
}
- Retreive IRazorLightEngine instance from controller constructor
private readonly IRazorLightEngine engine;
public HomeController(IRazorLightEngine engine)
{
this.engine = engine;
}
- Inject services to your templates
@inject MyProject.TestService myService