dependency-injectionservicestackfunq

Funq usage in ServiceStack


Thanks to Mythz for gist hint, a) or b) or c).

I will use Mythz's solution, it is accepted by me but there are concerns for it's pattern (ServiceLocator Pattern), you can check here for extra info.


Solution

  • There are a couple of ways to statically reference your AppHost instance. You can resolve a dependency via the IAppHost instance with:

    HostContext.TryResolve<T>();
    HostContext.Resolve<T>();
    HostContext.AppHost.TryResolve<T>();
    

    If for some reason you need to access the concrete Funq.Container, you can access it via the singleton:

    ServiceStackHost.Instance.Container
    

    Whilst inside a Service, Razor View Page, etc you can use:

    base.TryResolve<T>();