OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
853 stars 476 forks source link

MapODataServiceRoute builds the DI container and hides it #1111

Open jflord78 opened 6 years ago

jflord78 commented 6 years ago

We are migrating from Microsoft.AspNet.OData [5.9.1] to [6.1.0]. We are running into issues with trying to get our preexisting dependency injection infrastructure to work with the DI support in [6.1.0]. The call to MapODataServiceRoutebuilds a container and then stores it on the HttpConfigurationin a proprietary location. This is problematic because our existing infrastructure has to register it's own services in a composition root, and then use the built container to setup other dependency resolution points.

Assemblies affected

OData WebApi lib 6.1.0

Additional detail

We are trying to hack around this by implementing an IContainerBuilderthat simply captures the built container, but I'm wondering if there is a better way?

Ideally, we could simply pass in a prebuilt container instead of having MapODataServiceRoutedo all the container management behind the scenes. It would be up to the caller to populate the dependencies used by OData, but this can be handled with extension methods.

Example:

IServiceCollection services = new ServiceCollection();

services.AddMyServices();
services.AddODataServices();

IServiceProvider serviceProvider = services.BuildServiceProvider();

configuration.MapODataServiceRoute("MyRouteName", "MyRoutePrefix", serviceProvider);

Any guidance would be appreciated.

jnanneng commented 6 years ago

Web API OData does appear to allow one to specify a 'CustomContainerBuilder'... HttpConfigurationExtensions.cs -> UseCustomContainerBuilder.