I have being trying to use SystemWrapper to be able to mock file IO and other standard MS methods that I was writing my own wrappers for. However, I find that Castle Windsor, the IOC I am using, is having issues with it.
I am specifically working with IDirectoryInfo and DirectoryInfoWrap which implements it. I have registered like any other interface:
container.Register(Component.For<IDirectoryInfo, DirectoryInfoWrap>());
I have even done like this:
container.Register(Component.For<IDirectoryInfo>().ImplementedBy<DirectoryInfoWrap>());
But when I run my application I get this:
Can't create component 'SystemWrapper.IO.DirectoryInfoWrap' as it has dependencies to be satisfied.
'SystemWrapper.IO.DirectoryInfoWrap' is waiting for the following dependencies: - Service 'System.IO.DirectoryInfo' which was not registered. - Parameter 'path' which was not provided. Did you forget to set the dependency?
This make no sense to me. Why is it thinking the regular DIrectoryInfo is a "service" that needs to be registered? For giggles I tried registering DirectoryInfo with DirectoryInfoWrap but that gave me this:
Types System.IO.DirectoryInfo and SystemWrapper.IO.DirectoryInfoWrap are unrelated. That is not allowed. Are you sure you want to make them both services on the same component? Parameter name: x
If anyone has worked this out before please let me know. If it can't be then I will just continue writing wrappers by hand.
Thanks
So the answer was simple. The System Wrap constructor required a DirectoryInfo parameter. I've never dealt with a constructor parameter with Windsor. After researching that this was the solution:
Component.For<IDirectoryInfo, DirectoryInfoWrap>().DependsOn(Dependency.OnValue("directoryInfo", directoryInfo)