We use StructureMap 3.1.6.186 and are faced with the problem of overriding a specific plugin. In our case, we have a console application that we deploy to a remote server. The console application has a very distant implementation dependency, which requires some unwanted COM objects on the server. Since we know for sure that this particular dependency is not actually used in our Console application, we are trying to override a specific implementation that is problematic (IImageManipulator), with a fake implementation that I created directly in my main console application. This would make it easier to install these COM objects on the server and not break the console application.
As you will see from the code and comments below, neither explicit registration of IImageManipulator at the bottom of the container constructor, nor display injection after container assembly works as expected. Interestingly, when I get an instance of IImageManipulator in a console application, it gives me the desired implementation of FakeImageManipulator. However, when I get an instance of IEndItemService, then the main implementation is a different type that I don't want.
Any idea to override all implementations of a particular interface, even if there are other registries that have registered that interface? Thanks a ton!
public class FakeImageManipulator : IImageManipulator { public Dictionary<ImageMetaDataEnum, string> GetMetaData(Image image, params ImageMetaDataEnum[] desiredMetaData) { throw new NotImplementedException(); } } public override void ProgramLogic() { IContainer container = new Container(registry => { registry.ForSingletonOf<ITypeResolver>().Use<StructureMapTypeResolver>(); registry.ForSingletonOf<ILogger>().Use(() => MessageLogger.GetInstance()); registry.ForSingletonOf<IConfigParser>().Use(() => ConfigParser.GetInstance()); registry.Scan(scan => { scan.AssemblyContainingType<ServiceRegistry>(); scan.LookForRegistries(); });
}
Edit: also see this google group post that asks the same question: https://groups.google.com/forum/#!topic/structuremap-users/RAR_0JbOVGQ
structuremap structuremap3
jakejgordon
source share