我使用Nhibernate配置了我的服务堆栈项目,但我无法成功 调用我的api方法,我不断收到错误:
ResolutionException。无法解析NHibernate.ISession类型所需的依赖关系。
public class InventoryAppHost : AppHostBase
{
private readonly IContainerAdapter _containerAdapter;
public InventoryAppHost(NHibernate.ISessionFactory sessionFactory)
: base("Inventory", typeof(UserService).Assembly)
{
Container.Register(sessionFactory);
}
public override void Configure(Funq.Container container)
{
container.Adapter = _containerAdapter;
container.RegisterAutoWiredAs<UnitOfWork, IUnitOfWork>().ReusedWithin(ReuseScope.Request);
container.RegisterAutoWiredAs<UserDao, IUserDao>();
container.RegisterAutoWiredAs<UserServiceSystem, IUserServiceSystem>();
}
}
protected void Application_Start(object sender, EventArgs e)
{
var factory = SessionManager.SessionFactory;
(new InventoryAppHost(factory)).Init();
}
public partial class UserService : ServiceBase
{
private IUserServiceSystem _userServiceSystem { get; set; }
public IValidator<User> Validator { get; set; }
public UserService(IUserServiceSystem userServiceSystem)
{
_userServiceSystem = userServiceSystem;
}
public UserResponse Get(UserPkRequest request)
{
if (Validator != null)
Validator.ValidateAndThrow(new User { Id = request.Id }, "PkRequest");
var output = _userServiceSystem.Fetch(request);
if (output.Result == null)
throw new HttpError(HttpStatusCode.NotFound, "NullReferenceException", "User matching [Id = {0}] does not exist".Fmt(request.Id));
return output;
} }
下面是堆栈跟踪:
Funq.Container.GetEntry的堆栈跟踪[TService,TFunc](String serviceName,Boolean throwIfMissing)
在Funq.Container.ResolveImpl [TService](String name,Boolean throwIfMissing)
在lambda_method(Closure,Container)
在Funq.Container。&lt;&gt; c_ DisplayClass26 2.<RegisterAutoWiredAs>b__25(Container c)
at Funq.Container.ResolveImpl[TService](String name, Boolean throwIfMissing)
at lambda_method(Closure , Container )
at Funq.Container.<>c__DisplayClass26
2.b _25(容器c)
在Funq.Container.ResolveImpl [TService](String name,Boolean throwIfMissing)
在lambda_method(Closure,Container)
在Funq.Container.ResolveImpl [TService](String name,Boolean throwIfMissing)
在lambda_method(Closure,Container)
at ServiceStack.ServiceHost.ContainerResolveCache.CreateInstance(Type type,Boolean tryResolve)
at ServiceStack.ServiceHost.ContainerResolveCache.CreateInstance(Type type)
在ServiceStack.ServiceHost.ServiceController。&lt;&gt; c_ DisplayClass11.b _f(IRequestContext requestContext,Object dto)
at ServiceStack.ServiceHost.ServiceController.Execute(Object request,IRequestContext requestContext)
at ServiceStack.WebHost.Endpoints.EndpointHost.ExecuteService(Object request,EndpointAttributes endpointAttributes,IHttpRequest httpReq,IHttpResponse httpRes)
at ServiceStack.WebHost.Endpoints.RestHandler.GetResponse(IHttpRequest httpReq,IHttpResponse httpRes,Object request)
at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq,IHttpResponse httpRes,String operationName)