Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good pattern for naïve assembly initialization?

Tags:

c#

.net

Say we have several assemblies, and they all implement IAnimal, and we'd like go to one place to find out about the presence of the other IAnimal implementation.

features:

  • we don't want pre-knowledge outside of an assembly

  • there could be a register class / method within the assembly

  • it is preferable not to use reflection. So far this seems to be the only way though

discussion:

I imagined doing this statically via inheritance, however, I'm not aware of an assembly level initialization sequence.

like image 859
sgtz Avatar asked Feb 24 '23 08:02

sgtz


1 Answers

I suggest taking a look at MEF. It is practically designed for this kind of thing.

It does use reflection, as this is the mechanism created for such dynamic discovery. I doubt you will find a solution that doesn't use some level of reflection.

like image 51
Oded Avatar answered Feb 25 '23 21:02

Oded