4

This strikes me as likely to have an agreed best-practice answer, but I can't seem to find one anywhere.

I have an application that will load and use classes that implement a specific interface. The implementation classes will be written by someone else and I want to send them the minimum they need to successfully implement the interface.

So far the best I've come up with is the following:

The application solution that contains: A project that contains just the interface definition and compiles to a dll. A project for the application that uses the interface and references the dll.

A separate solution for an example implementation that builds to a dll and references the interface dll.

Is this the best way to do this? i.e. distribute a compiled version of the interface to anyone that needs to implement the interface.

I tried using just a copy of the interface source files in the example implementation and my application failed to recognise the class as implementing the interface. Is this to be expected or is my class loading code bugged (it does work when the example references the pre-compiled dll)?

Dan
  • 7,446
  • 6
  • 32
  • 46

2 Answers2

3

you should put your interface in an assembly and then distribute your assembly (or your whole project if needed) so that the other people who want to implement the interface just need to reference your assembly so they have access to the same interface (which is not the case if you just send the interface (.cs) file as your interface will be embedded in another assembly and thus will certainly have another namespace or assembly name and thats why your implementation class was not recognized as inheriting your interface cause basically it was not the same interface even if the methods and properties where the same ;))

i think your approach first is the best if you dont want people to change your code and just use the interface

otherwise just share the whole project containing the interface

0

That's the approach I've used, and seen in other projects - give the shared assembly a generic name such as MyApp.Interfaces, in case you end up with multiple shared interfaces.

An alternative approach is to use the Managed Extensibility Framework: http://msdn.microsoft.com/en-us/library/dd460648.aspx - but that may be overkill for a small project.

Saqib
  • 7,242
  • 7
  • 41
  • 55