Closed chriseldredge closed 10 years ago
Hi Chris,
Injecting pre-constructed controllers is not yet supported, but it's a valuable feature. How should dependency injection look?
Check out the construction of controllers in StreamControllerManager.GetStreamController. Very simple, one-line method which uses Activator.CreateInstance and stuffs that value into a concurrent dictionary:
public object GetStreamController(Type type)
{
return this.streamControllers.GetOrAdd(type, Activator.CreateInstance);
}
I wonder how ASP.NET vNext does DI.
At a minimum, allowing clients to provide their own subclass (or extracting an interface) for StreamControllerManager, and making GetStreamController virtual would be a start. That way clients can provide their own shims that hook into their container of choice.
It may make sense to allow clients to decide if their controllers should be singleton or bound to request as well, so I would not cache the result of GetStreamController when a client overrides it.
I've pushed an updated version which allows users to specify the delegate used to construct controllers when calling app.UseWebStream(...) - and I updated the wiki page to match.
Let me know what you think.
By the way, I renamed the package to Dapr.WebStreams.Server (s/WebStream/WebStreams/)
Fixed
Does this project support external instantiation of controller types? It would be useful if projects can wire in their own DI container like Autofac or Ninject. Perhaps it is already supported and just needs documentation.