developpement:dotnet:structuremap
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
developpement:dotnet:structuremap [2017/10/25 20:07] – créée sgariepy | developpement:dotnet:structuremap [2023/07/03 20:21] (Version actuelle) – créée sgariepy | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
[[http:// | [[http:// | ||
+ | |||
+ | Cette page est une prise de notes | ||
+ | |||
+ | |||
+ | Alternative : [[https:// | ||
+ | ====== Exemple avec ASP.NET Core ====== | ||
+ | |||
+ | 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.1508954877.txt.gz · Dernière modification : 2022/02/02 00:43 (modification externe)