Can't Resolve a service using AppHostBase.ResolveService<T> API in ServiceStack 4

StackOverflow https://stackoverflow.com/questions/21175224

  •  28-09-2022
  •  | 
  •  

سؤال

I'm using ASP.NET MVC 5 and attempting to resolve a few services using the example:

var authService = AppHostBase.Resolve<AuthService>();
authService.RequestContext = System.Web.HttpContext.Current.ToRequestContext();
var response = authService.Authenticate(new Auth
{
    UserName = model.UserName,
    Password = model.Password,
    RememberMe = model.RememberMe
});

or I've also tried:

using (var helloService = AppHostBase.ResolveService<HelloService>())
{
    ViewBag.GreetResult = helloService.Get(name).Result;
    return View();
}

In the first case I needed the RequestContext injected so I tried that approach and in the second case I was using the example which I understand has the RequestContext automatically injected through Funq.

ResolveService could not be found when I tried the second approach and in the first approach RequestContext is not a valid property. Am I missing something simple or has there been changes to the API?

هل كانت مفيدة؟

المحلول

The documentation does appear to be wrong for this as there is no longer a ResolveService<T> on AppHostBase. It needs to be updated due to changes in the Api.

You can do this in ServiceStack v4 with MVC:

var authService = HostContext.Resolve<AuthService>();
...
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top