Dynamically loading classes (with custom behavior) from different assemblies?

后端 未结 6 1081
栀梦
栀梦 2021-02-10 14:49

We are building an app for few customers, each has its own requirements along with the similar ones. We also want to keep all the code in the same app, not branch it, and the IF

6条回答
  •  广开言路
    2021-02-10 15:29

    I would use Unity, but as a Simple Factory.

    Unity Framework: How to Instantiate two classes from the same Interface?

    You could store your

    I am using Unity.2.1.505.2 (just in case that makes a difference).

      
        

    Here is the DotNet code.

    UnityContainer container = new UnityContainer();
    
    UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
                    section.Configure(container);
    
    string myKey = "John";  /* read from config file */ /* with this example, the value should be "myCarKey" or "myTruckKey"  */
    
    IVehicle v1 = container.Resolve(myKey); 
    

    See:

    http://msdn.microsoft.com/en-us/library/ff664762(v=pandp.50).aspx

    and

    http://www.sharpfellows.com/post/Unity-IoC-Container-.aspx

提交回复
热议问题