我正在尝试使用结构映射引导程序https://github.com/NancyFx/Nancy.Bootstrappers.StructureMap引导 nancyfx
这是我的设置:
protected override void ConfigureApplicationContainer(IContainer container)
{
container.Configure(x =>
{
x.ForSingletonOf<IRazorConfiguration>()
.Use<DefaultRazorConfiguration>();
x.ForSingletonOf<ISessionContainer>().Use<SessionContainer>();
x.For<IRepository>().LifecycleIs(new HttpContextLifecycle()).Use<Repository>();
x.Scan(scanner=>
{
scanner.TheCallingAssembly();
scanner.AddAllTypesOf<IRepository>();
});
});
base.ConfigureApplicationContainer(container);
}
public interface IRepository
{
void Save();
}
public class Repository:IRepository
{
ISessionContainer _session;
public Repository(ISessionContainer container)
{
_session = container;
}
public void Save()
{
}
}
当我使用var repo = ObjectFactory.GetInstance<IRepository>();
时,我得到了这个异常:
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily Infrastructure.IRepository, Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null