Funq usage in ServiceStack

前端 未结 1 1674
走了就别回头了
走了就别回头了 2021-02-09 23:07
  • How can I access Container instance out of controller?
  • I have to use Container.Resolve in my class but how can I access Container<
相关标签:
1条回答
  • 2021-02-09 23:37

    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>();
    
    0 讨论(0)
提交回复
热议问题