title: .NET Core - Globalization and Localization - Class library
body: <p>Following <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization" rel="noreferrer">this</a> documentation on how to implement globalization and localization using .NET Core, my goal is to store all my resources in a single global resource file located in a different project, (class library).</p>
  
  <p><strong>Project 1 - Startup.cs</strong></p>
  
  <pre><code>public class Startup
  {
      public Startup(IHostingEnvironment env)
      {
          var builder = new ConfigurationBuilder()
              .SetBasePath(env.ContentRootPath)
              .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
              .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  
          if (env.IsEnvironment("Development"))
          {
              builder.AddApplicationInsightsSettings(developerMode: true);
          }
  
          builder.AddEnvironmentVariables();
          Configuration = builder.Build();
      }
  
      public IConfigurationRoot Configuration { get; }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddApplicationInsightsTelemetry(Configuration);
  
          services.AddLocalization(lo =&gt; lo.ResourcesPath = "/MYCLASSLIBRARY"); //External project ~ How?
  
          services.AddMvc(config =&gt;
          {
              var policy = new AuthorizationPolicyBuilder()
                               .RequireAuthenticatedUser()
                               .Build();
              config.Filters.Add(new AuthorizeFilter(policy));
          });
  
          services.Configure&lt;RequestLocalizationOptions&gt;(
              opts =&gt;
              {
                  var supportedCultures = new List&lt;CultureInfo&gt;
                  {
                      new CultureInfo("en-US"),
                      new CultureInfo("sv-SE")
                  };
  
                  opts.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
                  opts.SupportedCultures = supportedCultures;
                  opts.SupportedUICultures = supportedCultures;
              });
      }
  
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          loggerFactory.AddConsole();
  
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          app.UseRequestLocalization(app.ApplicationServices.GetService&lt;IOptions&lt;RequestLocalizationOptions&gt;&gt;().Value);
  
          app.UseMvc();
  
          app.UseDefaultFiles();
  
          app.UseStaticFiles();
      }
  }
  </code></pre>
  
  <p><strong>Project 2 - Class library</strong></p>
  
  <p><a href="https://i.stack.imgur.com/8wcp6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8wcp6.png" alt="enter image description here"></a></p>
  
  <p><strong>Project 1 - Controller</strong></p>
  
  <pre><code>using MYCLASSLIBRARY; //External project
  
  [Route("api/[controller]")]
  public class HelloController : Controller
  {
      private readonly IStringLocalizer&lt;Test&gt; _localizer; //External project class
  
      public OrganisationController(IStringLocalizer&lt;Test&gt; localizer)
      {
          _mapper = mapper;
  
          _localizer = localizer;
      }
  
      [HttpGet("GetResource")]
      public string GetResource()
      {
          return _localizer["Help"];
      }
  }
  </code></pre>
  
  <h2>How can I reference an external project when setting ResourcesPath?</h2>
  
  <pre><code>services.AddLocalization(lo =&gt; lo.ResourcesPath = "/MYCLASSLIBRARY");
  </code></pre>