.NET Coreの汎用ホストでMicrosoft.Extensions.DependencyInjectionを使ったDI ContainerにAssembly Scanしてサービスを自動登録する簡易的な仕組みを作ったのでその備忘録です。 目次 目次 成果物 DI Containerに登録したいSericeの実装 基本的な仕組み 指定したAssembly内のInterface, Classを全て登録する関数 指定したInterfaceを継承しているClassのみを登録する関数 指定したGenericなInterfaceを継承したClassのみを登録する関数 使い方 問題点 おわり 成果物 Gistに上げています。 DI Containerに登録したいSericeの実装 例えば以下のCQRSっぽいコードがあったとします。 CQRSっぽいコード Microsoft.Extensions.De
Dependency Injection は Autofac を使っていたのだけど、.NET Core を使い始めると、Microsoft製のMicrosoft.Extensions.DependencyInjection がシンプルでよいという話を同僚から聞いたので、その基本をまとめておきたい。 Microsoft.Extensions.DependencyInjection 公式ページはこちら ASP.NET Core での依存関係の挿入 aspnet/DependencyInjection 実際に私はASP.NET というより、Azure Functions で使うことを想定していますので生の基本的な挙動を理解したいと思っています。 オブジェクトの注入 次のようなクライアントとそのインターフェイスがあるとします。 public interface ISomeClient { stri
Autofac is an addictive Inversion of Control container for .NET Core, ASP.NET Core, .NET 4.5.1+, Universal Windows apps, and more. Register Components Build up containers with lambdas, types, or pre-built instances of components. You can also scan assemblies for registrations. var builder = new ContainerBuilder(); // Register individual components builder.RegisterInstance(new TaskRepository()) .As
StructureMap is the oldest, continuously used IoC/DI container for .Net dating back to its first public release and production usage all the way back in June 2004 on .Net 1.1. The current 4.* release represents 12+ years of lessons learned in the StructureMap and greater .Net community -- while also wiping away a great deal of legacy design decisions that no longer make sense today. Learn more » F
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く