Closed Eilon closed 8 years ago
Possibly related: https://github.com/aspnet/Localization/issues/214
In 214, I am not seeing a solution. The problem is when I design a 3 tiered application this issue causes a circular reference. The main web portal module suddenly becomes a dependency to the Data and Business layer modules.
For example:
This is pretty standard N tier architecture.
Each of these projects need the resx files.
However, If I am forced to place MyProject.Resources.resx in the web portal app, now I have a circular reference problem. Because Portal project is dependent on EntityFramework and ViewModel projects (as it should be). Conversely, EntityFramework and BLL need those SAME resource strings and now becomes dependent on the Portal project!?.
@MrWinky we did the work to allow class library resources in #283. To enable this scenario you need to add ResourceLocationAttribute
to the AssemblyInfo of the class libraries so that the "main" project knows where to look for the resources.
Let us know if you have any trouble with that, or if I misunderstood and that doesn't actually resolve your issue.
On second thought I'll close this as it seems to be the exact use case #283, but feel free to re-open if the need arises.
@MrWinky we did the work to allow class library resources in #283. To enable this scenario you need to add
ResourceLocationAttribute
to the AssemblyInfo of the class libraries so that the "main" project knows where to look for the resources.
hi @ryanbrandenburg, could you please elaborate this answer? You say AssemblyInfo
of the class libraries. Which libraries? Where exactly to put the attribute?
@fabercs you should decorate your assembly by adding ResourceLocationAttribute
to the AssemblyInfo
. Have a look to this line for instance https://github.com/aspnet/Localization/blob/master/test/ResourcesClassLibraryWithAttribute/AssemblyInfo.cs#L7
@hishamco thank you for answer, this is my solution structure;
|--MyProject.Infrastructure
|--MyProject.Core
|--MyProject.Web
|--Controllers
|--ViewModels
|--Views
|--MyProject.Resources
|--Controllers
|--ViewModels
|--Views
Should I create an AssemblyInfo.cs
file under MyProject.Resources
and add the line [assembly: ResourceLocation("ResourceFolder")]
? Should I wrap all the files in a ResourceFolder
or keep it as is?
Yep, add it under MyProject.Resources
Should I wrap all the files in a ResourceFolder or keep it as is
Yes & No, but the important thing is resource naming, you can check the docs on this one
@hishamco I did lots of thing but I couldn't get it work. Is there any real world application that works like this way? I know resources and pages or classes follow namespace convention, but I couldn't understand how using an assemblyInfo solves this.
Here what I did;
Moved Resources
folder in Web project to new MyProject.Resources
class library project as shown my previous post. So, all resources wrapped inside a Resource
folder.
Added an AssemblyInfo.cs
in the root of MyProject.Resources
and added following line;
[assembly: ResourceLocation("Resources")]
In Startup.cs
, removed ResourcePath
option from the AddLocalization
middleware. (I tried with the option as well).
Last status is; services.AddLocalization()
Do we need any other configuration in Startup.cs
?
And project structure is as follows;
|--MyProject.Infrastructure
|--MyProject.Core
|--MyProject.Web
|--Controllers
|--ViewModels
|--Views
|--Customer
|--Index.cshtml
|--MyProject.Resources
|--Resources
|--Controllers
|--ViewModels
|--Views
|--Customer
|--Index.en-US.resx
|--Index.tr-TR.resx
|--SharedResource.cs
|--SharedResource.en-US.resx
|--SharedResource.tr-TR.resx
SharedResources are the only working part in project right now btw. I suspect AssemblyInfo
should be placed in Web
project, maybe?
@fabercs seems this issue is died, could you please file a new issue in the AspNetCore repo and copy your latest comment
@hishamco actually I have already created a new issue, https://github.com/aspnet/Mvc/issues/8739 I have also moved my last comment to there..
That's great, waiting for your reply there
Moved from https://github.com/aspnet/Mvc/issues/4723 Opened by @MrWinky
There are lots of great VNEXT articles explaining how to use RESX resources when the \Resources folder are in the VNEXT application's sub folder path.
However, I have an MVC application which requires I place the RESX files in a separate VNEXT class library dll in the solution and share it among projects (assume the separate project is called MyResourceProject). Maybe I should be using a different project type for sharing resource strings in a RESX?
The following does not work:
and
How do I point to a separate library path in an MVC VNEXT application?