Friday, 17 February 2012

StructureMap: No Default Instance exception

{"StructureMap Exception Code:  202\nNo Default Instance defined for PluginFamily BUSINESS_DOMAIN.Repository.IRepository`1[[BUSINESS_DOMAIN.EMERGENCY_SERVICE_TYPE, BUSINESS_DOMAIN, Version=, Culture=neutral, PublicKeyToken=null]], BUSINESS_DOMAIN, Version=, Culture=neutral, PublicKeyToken=null"}

This Exception often means you have not added the class (in this case IRepository) to the list of Registered types for the Container.

The rememdy:

Either add the type explicitly:

ObjectFactory.Initialize(x => { x.For<ABSTRACT_TYPE>().Use<CONCRETE_TYPE>(); } );

OR get StructureMap to scan the whole assembly:

ObjectFactory.Initialize(x => { x.Scan( scan => { scan.AssemblyContainingType<CONCRETE_TYPE>(); } ); } );

No comments:

Post a Comment