Reputation: 15931
I would like to be able to resolve an enumerable collection of IRepository<T> where T : IDocument
In my registry class I've added the following registration code:
this.For<IRepository<IDocument>>().Add<Repository<Document>>();
this.For<IRepository<IDocument>>().Add<Repository<AnotherDocumentType>>();
Both the classes Document
and AnotherDocumentType
implement the interface IDocument
, and Repository<T>
implements IRepository<T>
. I'm new to structure map, and I don't really understand the error message. All classes involved have default constructors.
Structuremap is throwing the following error Test Name: can_resolve_a_collection_of_document_repositories Test FullName: my.test.IoCTest.can_resolve_a_collection_of_document_repositories Test Source: d:\Projects\level\my\mtrunk\src\my.test\IoCTest.cs : line 46 Test Outcome: Failed Test Duration: 0:00:00.138309
Result Message: Test method my.test.IoCTest.can_resolve_a_collection_of_document_repositories threw exception: StructureMap.Exceptions.StructureMapConfigurationException: StructureMap configuration failures: Error: 104 Source: Registry: StructureMap.Configuration.DSL.Registry, StructureMap, Version=2.6.4.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223 Type Instance '613169b9-b8d9-4c80-868a-d6aa47e3d95c' (Configured Instance of my.data.Impl.Repositories.Repository
1[[my.domain.Document, my.domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], my.data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) cannot be plugged into type my.data.IRepository
1[[my.domain.IDocument, my.domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], my.data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullError: 104 Source: Registry: StructureMap.Configuration.DSL.Registry, StructureMap, Version=2.6.4.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223 Type Instance '2196350f-0c64-4bd2-92af-9946f1e11862' (Configured Instance of my.data.Impl.Repositories.Repository
1[[my.domain.AnotherDocumentType, my.domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], my.data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) cannot be plugged into type my.data.IRepository
1[[my.domain.IDocument, my.domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], my.data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullResult StackTrace: at StructureMap.Diagnostics.GraphLog.AssertFailures() in c:\BuildAgent\work\767273992e840853\src\StructureMap\Diagnostics\GraphLog.cs:line 68 at StructureMap.Container.construct(PluginGraph pluginGraph) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Container.cs:line 576 at StructureMap.Container..ctor(PluginGraph pluginGraph) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Container.cs:line 55 at StructureMap.ObjectFactory.Initialize(Action`1 action) in c:\BuildAgent\work\767273992e840853\src\StructureMap\ObjectFactory.cs:line 65 at my.test.IoCTest.can_resolve_a_collection_of_document_repositories() in d:\Projects\level\my\mtrunk\src\my.test\IoCTest.cs:line 51
Upvotes: 1
Views: 5546
Reputation: 6826
I had the same error code.
I made the dumb mistake of not adding the Interface to the Class.
BEFORE
public class MyClass //No Interface
AFTER
public class MyClass : IMyClass
"That's like so me dude!"
Upvotes: -1
Reputation: 3804
The problem isn't StructureMap but the way you're using generics.
Does IRepository<IDocument> foo = new Repository<Document>();
build?
Make IRepository covariant (i.e. public interface IRepository<out T> where T : IDocument
, the out
part is important) and try again.
Upvotes: 2