samedi 11 juillet 2015

C# - Assign Mocked dependecies that are Imported from MEF

I'm using MEF for dependency injection and I'm at this point writing a Unit Test in which I'd have to inject a mocked dependency, but I have declared it as { get; protected set; } which renders me unable to do it.

The dependency is imported using the [Import] attribute, which means it isn't passed via constructor or anything similar.

What is the right approach, and by "right" I mean it doesn't violate any principle like SOLID and similar, to solve this inconvenient?

Code:

[Import]  // MEF is able to inject it even tho it's set accessor is protected
IMyDependencie MyDependency { get; protected set; }

Aucun commentaire:

Enregistrer un commentaire