View classes (RazorPage<T>) support services being injected in their constructors, as illustrated in the following code snippet:
public class MyPage : RazorPage<dynamic>
{
public MyPage(IMyService svc)
{
//constructor injection
}
}
Views also support having services injected into them. Just declare an @inject element in the .cshtml file with the service type to retrieve and the local variable to hold it, probably at the beginning of the view, like this:
@inject IHelloService Service
After this, you can use the injected Service variable, like this:
@Service.SayHello()
There may be the need to either fully qualify the type name or add a @using declaration for its namespace.
Let's see now how to have our application respond in different languages.