[英]sharp-repository custom repositories with structuremap
Using StructureMap 3.0.3.116 to initialize services with custom IRepository<,> with SharpRepository, structuremap still cannot find concrete class using the default convention. 使用StructureMap 3.0.3.116通过带有SharpRepository的自定义IRepository <,>初始化服务时,structuremap仍无法使用默认约定找到具体的类。
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'
没有注册默认实例,并且无法自动确定类型'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();
});
});
Looks like I got it to work by adding [DefaultConstructor] attribute to the constructor that had no parameters. 似乎我通过向没有参数的构造函数中添加[DefaultConstructor]属性来使其工作。 It was trying to use the greediest constructor.
它试图使用最贪婪的构造函数。
http://docs.structuremap.net/UsingAttributes.htm#section2 http://docs.structuremap.net/UsingAttributes.htm#section2
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. 尝试在IBlogImagerepository中创建IRepository <,>时可能实际上是引发异常,而不是无法找到IBlogImageRepository接口本身。 The inner exception might give more details.
内部异常可能会提供更多详细信息。
I would try using the SharpRepository.Ioc.StructureMap NuGet package and then adding 我会尝试使用SharpRepository.Ioc.StructureMap NuGet包,然后添加
x.ForRepositoriesUseSharpRepository();
to your initialization method and seeing if this helps. 初始化方法,看看是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.