0

I want to build a flexible reporting system for my application. So far I only have a concept in my head and need some tips on implementation. I'm using Crystal Reports to render reports and I know how to load reports dynamically.

Now, the idea is that every report will be packaged as a separate assembly (.dll). The reporting framework will be loading every custom report and communicating with it via clearly defined interface like this:

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

Also, there will be some base implementation (as an abstract class) that will handle some common operations on the reports (like binding to data source, etc.):

public abstract class Report
{
    ...
}

Inside every dll there will be an implementation of concrete class, representing this or that report:

public class CustomersReport : Report
{
    ...
}

Now, I have to figure out the following:

1) How to dynamically locate and load the dll?

2) How to create an instance of concrete class (CustomerReport) and cast it to IReport in order to call necessary methods on it?

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

Thanks in advance.

EDIT:

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

Pavel Bastov
  • 6,911
  • 7
  • 39
  • 48

3 Answers3

1

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

viraptor
  • 33,322
  • 10
  • 107
  • 191
  • Thanks for the link, viraptor. Seems to be a really good source of information. Still, I would like to implement smth on my own (not-invented-here syndrome?) just for experience. – Pavel Bastov May 13 '09 at 02:32
1

See this: Problem with dynamic loading of a dll into my program Is doing exactly what you want wihtout all the YAGNI around it.

Community
  • 1
  • 1
gbianchi
  • 2,129
  • 27
  • 35
0

You can consider MEF from Microsoft. It is a composition engine that can be set up to monitor a local folder and automatically load assemblies that export parts (implementation of IReport in your case) that you're interested in. We do have a system like that we implemented sometime ago. We have a single assembly with reports that we load into a separate application domain and reload if the file version has changed. Then we use .NET remoting to communicate between app domains. We considered using Add-in framework from Microsoft but we found it to be very complex and imposing and decided it was too heavy and complex in our case.

Mehmet Aras
  • 5,284
  • 1
  • 25
  • 32