developpement:dotnet:structuremap
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
developpement:dotnet:structuremap [2017/10/25 20:10] – sgariepy | developpement:dotnet:structuremap [2023/07/03 20:21] (Version actuelle) – créée sgariepy | ||
---|---|---|---|
Ligne 6: | Ligne 6: | ||
- | ====== | + | Alternative : [[https:// |
+ | ====== | ||
+ | Installer le package StructureMap: | ||
+ | |||
+ | < | ||
+ | |||
+ | PM> Install-Package StructureMap | ||
+ | |||
+ | Le package '' | ||
+ | |||
+ | Le package '' | ||
+ | |||
+ | Créer un service quelconque. | ||
+ | |||
+ | <code csharp> | ||
+ | public interface ICarsProviderService | ||
+ | { | ||
+ | Dictionary< | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | Dans '' | ||
+ | |||
+ | <code csharp> | ||
+ | services.AddSingleton< | ||
+ | </ | ||
+ | |||
+ | Ensuite, dans le contrôleur : | ||
+ | |||
+ | <code csharp> | ||
+ | private readonly ICarsProviderService _carsProviderService; | ||
+ | |||
+ | public CarsController(ICarsProviderService carsProviderService) | ||
+ | { | ||
+ | this._carsProviderService = carsProviderService; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Et on peut utiliser le service: | ||
+ | |||
+ | <code csharp> | ||
+ | // GET: api/cars | ||
+ | [HttpGet] | ||
+ | public IEnumerable< | ||
+ | { | ||
+ | return this._carsProviderService.GetCars().Select(x => x.Value); | ||
+ | } | ||
+ | </ | ||
+ | ====== Registres ====== | ||
+ | |||
+ | Les '' | ||
+ | |||
+ | |||
+ | <code csharp> | ||
+ | public class SomethingRegistry : StructureMap.Registry | ||
+ | { | ||
+ | public SomethingRegistry() | ||
+ | { | ||
+ | this.For< | ||
+ | | ||
+ | this.For< | ||
+ | this.For< | ||
+ | | ||
+ | this.For< | ||
+ | } | ||
+ | } | ||
+ | </ | ||
developpement/dotnet/structuremap.1508955002.txt.gz · Dernière modification : 2022/02/02 00:43 (modification externe)