Using a Strategy and Factory Pattern with Dependency Injection

后端 未结 5 433
有刺的猬
有刺的猬 2020-12-05 15:50

I am working on a side project to better understand Inversion of Control and Dependency Injection and different design patterns.

I am wondering if there are

5条回答
  •  忘掉有多难
    2020-12-05 16:06

    Register and resolve them using your Strategy Type strings.

    Like this:

    // Create container and register types
    IUnityContainer myContainer = new UnityContainer();
    myContainer.RegisterType("Fedex");
    myContainer.RegisterType("DHL");
    
    // Retrieve an instance of each type
    IShippingStrategy shipping = myContainer.Resolve("DHL");
    IShippingStrategy shipping = myContainer.Resolve("Fedex");
    

提交回复
热议问题