there
Probably what I am asking is impossible, but nevertheless here is my problem and question. First of all this is C# and .NET.
I would like to define an empty implementation (empty methods, functions returning defaults) of a class to an interface in such a way if I change the interface I will not need to adapt the code. Unfortunately I can not generate the implementation containing assembly and I can define a dynamical mock on it because instantiation is done automatically via reflection. Here is the problem explained more broadly:
I have a dll/assembly let us call it IMyInterface.dll that contains an interface: IMyInterface.
Layers above I have the implementation in a separate dll/assembly let us call it MyInterfaceImplementation.dll.
In the middle/between I have an automatized test framework that can depend on IMyInterface.dll but not on MyInterfaceImplementation.dll.
Now this test framework uses the production code infrastructure that instantiates types via reflection. It is a dependency injection type framework. So you say to the production code infrastructure give me this interface implementation from this assembly.
In our case you say give me a IMyInterface from MyInterfaceImplementation.dll. In the test framework you can not depend from MyInterfaceImplementation so you define a fake/stub/mock class based on IMyInterface in a third assembly lets call it: MyInterfaceFakeImplementation.dll
In the test framework you say give me a IMyInterface from MyInterfaceFakeImplementation.dll and you are fine.
Note: Do to our modules hierarchy it is not possible to restructure the dependencies.
When you write your code in the MyInterfaceFakeImplementation.dll you write down like this:
class MyInterfaceFakeImplementation : IMyInterface
{
// IMyInterface implementation.
}
Now what I would like is to provide is dynamic class of IMyInterface, so when interface changes than I do not need to adapt the fake.
Very shorty here is what I want:
Given:
IMyInterface interface in IMyInterface.dll
MyInterfaceFakeImplementation impementation of IMyInterface in MyInterfaceFakeImplementation.dll
MyInterfaceFakeImplementation has empty functions and returns default values.
When:
I change IMyInterface (Ex. change a functions signature).
Then:
I do not need to change MyInterfaceFakeImplementation, just recompile MyInterfaceFakeImplementation.dll. Note: It is not possible to possible to generate this assembly, needs to be compiled.
Here is a workaround.
Do a fake implementation (class) next to IMyInterface in the IMyInterface.dll, let us call it MyInterfaceFakeBase. In the MyInterfaceFakeImplementation.dll derive the MyInterfaceFakeImplementation from this base class MyInterfaceFakeBase and leave it empty. When changing the interface (IMyInterface) adapt MyInterfaceFakeBase and never worry about MyInterfaceFakeImplementation and MyInterfaceFakeImplementation.dll.
Bye Laszlo
Aucun commentaire:
Enregistrer un commentaire