I want to process different types of documents in the same way in my application Therefore: I have such a common interface.
public interface IDocHandler<T>where T: class { T Document { get;set;} void Load(T doc); void Load(string PathToDoc); void Execute(); void Execute(T doc); }
And for different types of documents, I implement this interface.
eg:
public class FinanceDocumentProcessor:IDocumentHandler<ReportDocument> {} public class MarketingDocumentProcessor:IDocumentHandler<MediaDocument> {}
Then, of course, I can do something like this:
IDocumentHandler<ReportDocument> docProc= new FinanceDocumentProcessor();
It would be interesting to know how I could introduce T at runtime to make the line above loosely coupled ...
IDocumentHandler<ReportDocument> docProc = container.resolve("FinanceDocumentProcessor());
but I want to decide for each configuration I want to have my FinanceDomcumentProcessor or my MarketingDocumentProcessor ... so I would have to type T to the left site too ... Since I have to use C # 2.0, I can’t use the magic word “var”, which in this case would help a lot ... but how can I create this to be open and flexible ...
Sorry for the misunderstanding and thanks for all the comments, but I have another example for my call (maybe I use the wrong design for this) ... But I give it a try: in the same situation, but in a different explanation
Example image I have:
ReportingService, Crystal, ListAndLabel Three different types of reports. I have a generic Handler IReportHandler<T> (will be the same as above), this Handler provides all the functions for processing a report document. for example
ChrystalReportHandler:IReportHandler<CrystalReportDocument>
Now I want to use the Unity platform (or some other framework) for dependency injection, to decide through the configuration whether I want to use Crystal, Reportingservices or List and Label.
When I specify my mapping, I can enter my ChrystalReportHandler , but how can I enter T on the left or better the word Type ReportDocument .
IReportHandler<T (this needs also to be injected)> = IOContainer.Resolve(MyMappedType here)
My problem is the left site, of course, because it is associated with the type, but I have a mapping ... can I create an object based on the mapping and assign a displayed type? or basically enter T from the left side too? Or this approach is not suitable for this situation.