use Activator.CreateInstance to dynamically load the concrete class and avoid Circular references

I have a Factory class that creates number of classes to handle different XML responses, returned by Web Service. All of them are derived from some base class GwsResponse and created depending on the top name element name.
Previously factory and all created object classes were located in the same DLL.
Now we need to increase number of handled responses, but we want new classes to create in separate extension DLL. 

We are going to use Activator.CreateInstance to dynamically load the concrete class and avoid Circular references

The names of classes and assembly will be defined in config file.

The approach is well described in the thread:    

Circular references not possible?

Similar idea suggested in Creating an object dynamically using Reflection and running in a seperate thread

 

Links about Dependency Injection (pointed by TheCPUWizard)

Design Patterns Dependency Injection(MSDN Magazine, September 2005)

Unity competitors discussin on forum and post Microsoft releases Unity, an IoC library

 
 
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Monday, May 05, 2008 11:36 PM
Print

Comments on this entry:

# re: use Activator.CreateInstance to dynamically load the concrete class and avoid Circular references

Left by TheCPUWizard at 5/7/2008 1:26 PM
Gravatar
That is one approach, but with a potential for a performance hit (please note the word potential)...

A more "modern" approach is to use Dependancy Injection. Alas, I do not have a link handy, but this was covered in depth in MSDN magazine about 2-3 months ago.

One big plus....there are already libraries that provide sophisticated implementation!

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910