Confining an ASP.Net Core web application with one asset record (per language) isn’t as simple as I have suspected. So here I am sharing a straight forward and simple approach to do only that in under 5 minutes.
This post was tried in ASP.Net Core 2.1.
To begin with, we should comprehend the three primary concerns that should be restricted in an ASP.Net Core application.
- Information explanation limitation.
- Controllers confinement.
- View confinement.
These angles should be changed.
Initially, we should make the required records (ways and namespaces ought to be as depicted):
We need a Resources organizer in the undertaking root.
At that point make asset documents in this organizer, here is a rundown of my records:
Presently make a vacant class called SharedResources in the base of the task and with the namespace of the undertaking.
You’re currently prepared to begin arranging the limitation!
Information explanation confinement
Make an unknown supplier utilizing the vacant class from prior.
This part is for Controllers or any code that would more often than not utilize the IStringLocalizer.
Solicitation the IStringLocalizer from the DI with the SharedResources class.
Here you have to make your very own usage of a Localizer and put this class in the Resources organizer.
I just made a trifling localizer that utilizes the IStringLocalizer in the background (This clearly can be improved).
At that point infuse this Localizer rather than the default IViewLocalizer.
For my situation, I infused the SharedViewLocalizer in the _ViewImports and named the case as Localizer. Along these lines, I just needed to alter one record to refresh every one of the perspectives in the undertaking.
That is it! You’ve limited your ASP.Net Core application in under 5 minutes and you now just have one asset document to keep up.