Flexible reporting system with dynamically loaded assemblies

I want to create a flexible reporting system for my application. So far, I only have a concept in my head and need advice on how to implement it. I am using Crystal Reports to render reports and I know how to load reports dynamically.

Now the idea is that each report will be packaged as a separate assembly (.dll). The reporting framework will download each custom report and link to it through a well-defined interface as follows:

public interface IReport
{
    string GetTitle();
    string GetDescription();
    void SetParameter();
    void Print();
}
      

In addition, there will be a base implementation (as an abstract class) that will handle some common operations on reports (such as binding to a data source, etc.):

public abstract class Report
{
    ...
}

      

Inside each DLL, a specific class will be implemented that represents a particular report:

public class CustomersReport : Report
{
    ...
}

      

Now I have to figure out the following:

1) How to dynamically find and load a DLL?

2) How to create an instance of a concrete class (CustomerReport) and pass it to IReport to call the necessary methods on it?

Have you ever implemented such an extensible system? Could you please share your knowledge / code snippets?

Thanks in advance.

EDIT:

While researching this question, I found Jon Skeet's article on Plug-ins and Cast Excceptions that might be helpful.

0


a source to share


3 answers


See this: Problem with dynamically loading dlls into my program Does exactly what you want from all the YAGNI around it.



+1


a source


Have a look at Mono.Addins (it's an MIT license, so it's ok with closed software). From your description, it does what you need. It mainly uses dependency tree + interface based plugins. It has its own manager for loaded DLLs and its objects are based on the loaded interface, so you don't need any more magic caste to name something.



+1


a source


You can consider Microsoft's MEF . It is a layout engine that can be configured to monitor a local folder and automatically load assemblies that export the parts (the IReport implementation in your case) that interest you. We have such a system that we once implemented. We have one assembly with reports that we load into a separate application domain and reload if the file version has changed. We then use .NET remoting to communicate across application domains. We considered using add-ons from Microsoft, but we found it to be very complex and impressive, and decided that in our case it was too heavy and complex.

0


a source







All Articles