我有一个简单的 mvc 应用程序,它有 3 层
- Ui => 引用了 Common And Services
- 常见的
- 服务 => 引用了 Common
我在公共层定义我的服务合同并在服务层实现它
//Common layer
public interface IPersonService
{
void Foo();
}
//Services layer
public classPersonService:IPersonService
{
void Foo()
{
//To DO
}
}
在我的 Global.asax 中,我为初始 Structuremap 容器编写了这段代码
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
}
现在,当我想像这样从 IPersonService 获取实例时,在我的控制器中
var personService= ObjectFactory.GetInstance<IPersonService>();
我收到这个错误
没有注册默认实例,无法自动确定类型“*.IPersonService”
有解决这个问题的想法吗?