unitycontainer / microsoft-dependency-injection

Unity.Microsoft.DependencyInjection package
Apache License 2.0
63 stars 36 forks source link

Cannot use with extended UnityContainer #61

Closed cguedel closed 4 years ago

cguedel commented 4 years ago

We're having an extended version of IUnityContainer for testing purposes in place. We cannot use that container instance with these extensions, as they (for some unknown reason) cast the instance passed as IUnityContainer (in the method signature) to UnityContainer causing a casting exception.

pnmcosta commented 4 years ago

I think that's cause the current release is not using the Abstractions from Unity, please try this PR instead, https://github.com/unitycontainer/microsoft-dependency-injection/pull/58 that's been updated to 5.11.1.

ENikS commented 4 years ago

Not sure what is the problem here. Could you please provide more info?

cguedel commented 4 years ago

The problem is that the code is littered with casts that assume that a IUnityContainer instance is always of type UnityContainer.

E.g. https://github.com/unitycontainer/microsoft-dependency-injection/blob/master/src/ServiceProviderExtensions.cs#L48 or https://github.com/unitycontainer/microsoft-dependency-injection/blob/master/src/ServiceProviderFactory.cs#L67

If the methods signature suggests to accept an IUnityContainer instance, I don't see the need to cast it to UnityContainer. If that's needed, I suggest to change the signature to accept only the concrete type.

ENikS commented 4 years ago

UnityContainer type is required to register extensions.