Reputation: 1233
Using StructureMap 3.0.3.116 to initialize services with custom IRepository<,> with SharpRepository, structuremap still cannot find concrete class using the default convention.
public interface IBlogImageRepository : IRepository<BlogImage,int>
{
}
public class BlogImageRepository :
ConfigurationBasedRepository<BlogImage, int>, IBlogImageRepository
{
Error:
No default Instance is registered and cannot be automatically determined for type 'My.Assembly.Repositories.IBlogImageRepository'
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.Assembly("S3.Libs");
scan.IncludeNamespace("S3.Libs.Repositories");
scan.IncludeNamespace("S3.Libs.Services");
scan.WithDefaultConventions();
scan.ConnectImplementationsToTypesClosing(typeof (IRepository<,>));
});
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
});
Upvotes: 0
Views: 351
Reputation: 1233
Looks like I got it to work by adding [DefaultConstructor] attribute to the constructor that had no parameters. It was trying to use the greediest constructor.
http://docs.structuremap.net/UsingAttributes.htm#section2
Upvotes: 1
Reputation: 13510
It might be that it is actually throwing the exception when trying to create the IRepository<,> within the IBlogImagerepository as opposed to not being able to find the IBlogImageRepository interface itself. The inner exception might give more details.
I would try using the SharpRepository.Ioc.StructureMap NuGet package and then adding
x.ForRepositoriesUseSharpRepository();
to your initialization method and seeing if this helps.
Upvotes: 0