Integration test for IoC registrations?
-
Hi, for our project we use Windsor Castle to do IoC. This means that we also let the IoC container resolve the needed constructor arguments. But for some cases (wrappers, view models, etc.) we also need to pass some ctor arguments which are only known at runtime and from my opinion are needed to create a valid object. For this we use generic factories like:
interface IMyWrapperFactory
{
IMyWrapper CreateWrapper(string key);
}For this to work I have IoC registered that factory as well as IMyWrapper, where the implementation of IMyWrapper only has one ctor overload with the string argument. Problem: we also have created an integration test which instantiates all registered components to ensure that everything can be resolved. But this fails for obvious reasons with IMyWrapper, as the string argument is not registered! I would be very happy if you could tell me what you think about it. 1. Is there a way to let certain components exclusively be instantiated by generic factories so the test could differ and it would not be possible to acquire an instance directly without using the needed string argument? 2. Am I wrong and it is generally bad practice to provide runtime parameters to constructors? 3. If not, would you limit your freedom of doing so just to make the integration test check 100% well? Best regards Alex
-
Hi, for our project we use Windsor Castle to do IoC. This means that we also let the IoC container resolve the needed constructor arguments. But for some cases (wrappers, view models, etc.) we also need to pass some ctor arguments which are only known at runtime and from my opinion are needed to create a valid object. For this we use generic factories like:
interface IMyWrapperFactory
{
IMyWrapper CreateWrapper(string key);
}For this to work I have IoC registered that factory as well as IMyWrapper, where the implementation of IMyWrapper only has one ctor overload with the string argument. Problem: we also have created an integration test which instantiates all registered components to ensure that everything can be resolved. But this fails for obvious reasons with IMyWrapper, as the string argument is not registered! I would be very happy if you could tell me what you think about it. 1. Is there a way to let certain components exclusively be instantiated by generic factories so the test could differ and it would not be possible to acquire an instance directly without using the needed string argument? 2. Am I wrong and it is generally bad practice to provide runtime parameters to constructors? 3. If not, would you limit your freedom of doing so just to make the integration test check 100% well? Best regards Alex
you can use MOQ for mocking and IOC for running the test cases.