2

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?

Scott
  • 21,211
  • 8
  • 65
  • 72
Nadeem
  • 83
  • 4

1 Answers1

1

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>();
...
Scott
  • 21,211
  • 8
  • 65
  • 72
  • 1
    @Scott or the shorter alias **HostContext.ResolveService()**. – mythz Jan 18 '14 at 02:56
  • @mythz Good call, that's easier. – Scott Jan 18 '14 at 14:01
  • @Scott yep, also no need to set the Request as it already [uses HttpContext.Current by default](https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/HostContext.cs#L322-L328). – mythz Jan 18 '14 at 14:04
  • 1
    That was great, most of the examples I had seen all used the old API, this is much easier. – Nadeem Jan 18 '14 at 16:30