I'm currently attempting to use ServiceStack in a SignalR application that I am writing that is part of a large MVC 4.5 application.
I currently have a class in the App_Start folder that is starting my Hub. My question is how do I get a reference to the container as shown in the wiki for ServiceStack.
container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));
container.Register<ICacheClient>(c => (ICacheClient)c.Resolve<IRedisClientsManager>().GetCacheClient());
What I am doing is using Redis as the Development cache tier and planning on using our exisitng membase as the production cache tier.
How do I get container?
To resolve dependencies from ServiceStack's IOC outside servicestack you can use either:
var foo = HostContext.TryResolve<IFoo>(); //null if doesn't exist
var foo = HostContext.Resolve<IFoo>(); //throws if IFoo doesn't exist
There are a few to access the Container outside from of outside of ServiceStack, the quickest way is:
var container = HostContext.Container;
Which is a shorthand way of accessing it via the IAppHost
singleton:
HostContext.AppHost.Container
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With