我很难理解为什么我的 Manager 类在通过 Service 类中的这个示例 POST 方法处理请求的上下文中为空。我注册了 Manager 和它的依赖项,就像这个例子一样,它似乎注册得很好。我可以让它工作的唯一方法是,如果我告诉属性去并通过 apphost 引用中的容器来 resolveNamed。谢谢!
public static class TemplateContainer
{
public const string DomainName = "Template";
public static Funq.Container Configure(Funq.Container container)
{
container.Register<IUOWMongo<TemplateMongoContext>>(DomainName, c =>
new UOWMongo<TemplateMongoContext>(
c.ResolveNamed<string>(Constants.NamedString)
)
).ReusedWithin(Funq.ReuseScope.Request);
container.Register<IMongoTemplateRepository>(DomainName, c =>
new MongoTemplateRepository<TemplateMongoContext>(
c.ResolveNamed<IUOWMongo<TemplateMongoContext>>(DomainName)
)
).ReusedWithin(Funq.ReuseScope.Request);
container.Register<ITemplateDataManager>(DomainName, c =>
new TemplateDataManager(c.ResolveNamed<IMongoTemplateRepository>(DomainName))
).ReusedWithin(Funq.ReuseScope.Default);
return container;
}
}
public class TemplateService : ServiceStack.ServiceInterface.Service
{
public ITemplateDataManager Manager { get; set; }
public GetTemplateResponse Post(GetTemplateRequest request)
{
var response = new GetTemplateResponse();
**// Manager is null here!!!
// Only way I can get it to work is if I do this:
Manager = AppHostBase.Instance.Container.ResolveNamed<ITemplateDataManager>("Template");**
return response;
}
}