Please read section on the .NET Core Container Adapter:
any dependencies registered .NET Core Startup are also available to ServiceStack but dependencies registered in ServiceStack’s IOC are only visible to ServiceStack.
So if you need dependencies available to both ServiceStack and external ASP.NET Core features like MVC you need to register them in your Startup.ConfigureServices()
.
Plugins
From your link:
public override void Configure(Funq.Container container)
{
var serverEventsFeature = new ServerEventsFeature();
// bind server events
serverEventsFeature.Register(this);
container.AddSingleton(new Engine(container.Resolve<IServerEvents>()));
}
Plugins should never be called directly like this, they're expected to be registered in the Plugins collection:
Plugins.Add(new ServerEventsFeature());
Plugins are registered after Configure()
is run, if you want to register a dependency that uses IServerEvents
registered by the ServerEventsFeature
you would need to either register your dependency with a factory function, i.e:
container.AddSingleton<ICacheClient>(c =>
new Engine(c.Resolve<IServerEvents>()));
Alternatively you can register a singleton instance an AfterInitCallbacks
which is run at the end of AppHost initialization, e.g:
AfterInitCallbacks.Add(host => {
container.AddSingleton<ICacheClient>(
new Engine(c.Resolve<IServerEvents>()));
});
If you wanted to register a singleton that any other Plugin registered you can have your plugin to implement IPostInitPlugin which runs AfterPluginsLoaded()
after all plugins are registered:
public class MyPlugin : IPlugin, IPostInitPlugin
{
public void Register(IAppHost appHost) {}
public void AfterPluginsLoaded(IAppHost appHost)
{
appHost.GetContainer().AddSingleton<ICacheClient>(c =>
new Engine(c.Resolve<IServerEvents>()));
}
}