Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pableess committed Jul 10, 2020
2 parents ee7dd0a + fd91eee commit eb1d9cc
Showing 1 changed file with 59 additions and 5 deletions.
64 changes: 59 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,73 @@
# Owin.Localization
Port of AspNetCore localization middleware (Microsoft.AspNetCore.Localization) to owin middleware. The allows a similar programming model as AspNetCore localization request providers making it much eaiser to write custom providers that multi-target both Owin and AspNetCore.
# dotnet localization ex

Localization middleware sets the requests culture and ui culture based a series of pluggable request culture providers.
This project contains the following localization enhancements for .NET web applications.

Includes support for Accept-Header, Cookie, and Query string providers.
1. Adds dependency injection support for IRequestCultureProviders in AspNetCore
- Why? The AspNetCore Localization middleware allows only the addition of Provider instances to the RequestCultureOptions. For simple providers this is not a problem because the culture can be determined from information on the request. However, more complex custom providers may use external systems like databases, web services, distributed caches etc. This allows the providers to be injected per request allows these dependencies to work much better with other Dependency Injection oriented services.

2. Provides a port of AspNetCore localization middleware (Microsoft.AspNetCore.Localization) to owin middleware.
- This allows a similar programming model as AspNetCore localization request providers making it much eaiser to write custom providers that multi-target both Owin and AspNetCore. This support also contains support for dependency injection of the providers.

See https://github.com/dotnet/aspnetcore/tree/master/src/Middleware/Localization for details and documentation.

### Packages

This project provides the following packages:

+ AspNetCore.Localization.DependencyInjection
- Dependency injection support for AspNetCore localization middleware culture providers
+ Owin.Localization
- Port of Microsoft.AspNetCore.Localization middleware to OWIN middleware. Also adds dependency injection support
+ Owin.Localization.Autofac
- Autofac container integration
+ Owin.Localization.Unity
- Unity container integration


### Installing

The package is available via NuGet.
The packages are available via NuGet.

AspNetCore packages
```
dotnet add package AspNetCore.Localization.DependencyInjection
```
OWIN packages
```
Install-Package Owin.Localization
Install-Package Owin.Localization.Autofac
Install-Package Owin.Localization.Unity
```
# Usage

## AspNetCore

```csharp
// in ConfigureServices
services.AddScoped<TestCultureProvider>();

...

// in RequestLocalizationOptions configuration
RequestLocalizationOptions options = new RequestLocalizationOptions().AddInitialInjectedProvider<TestCultureProvider>();

```

## OWIN

The owin usage is pretty much the same as using AspNetCore localization middleware. See https://github.com/dotnet/aspnetcore/tree/master/src/Middleware/Localization for details and documentation.

### Dependency Injection with Owin
The dependency injection support with OWIN requires an addition extension method is called on the RequestCultureOptions before calling .AddInjectedProvider<T>() or .AddInitialInjectedProvider<T>()

```csharp
var options = new RequestLocalizationOptions().UseUnityInjection(UnityConfig.Container);

or

var options = new RequestLocalizationOptions().UseAutofacInjection();
```
* the providers also need to be registred as scoped services with the container

### AspNet MVC projects
AspNet MVC projects require a small amount of additonal code to ensure that the assigned culture flows accross from the OWIN middleware to the AspNet request MVC pipeline, because of the way AspNet handles async Owin middleware.
Expand Down

0 comments on commit eb1d9cc

Please sign in to comment.