Azure / azure-functions-dotnet-extensions

Azure Functions .NET extensions
MIT License
75 stars 41 forks source link

Registering implementation type X is not assignable to service type IX when using Generics #55

Closed ruslanss closed 1 month ago

ruslanss commented 3 years ago

is this a known issue limitation?

I have added code to reproduce it here: https://github.com/ruslanss/azure-functions-dotnet-extensions/tree/service_registration_bug

this type of service registration doesn't appear to be supported:

builder.Services.AddSingleton<IValidator<WhateverCommand>, NullValidator>();

Error on host startup:

[2020-10-22T20:12:11.169] A host error has occurred during startup operation '3a905cf7-b8f9-4dad-868a-ae23c7e8c1db'. [2020-10-22T20:12:11.170] Microsoft.Azure.WebJobs.Script.WebHost: Registering implementation type Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.InjectionTest.NullValidator is not assignable to service type Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.InjectionTest.IValidator.

remiX- commented 2 years ago

Hey Ruslanss, did you ever manage to resolve this? I'm having issues with this after updating my Function App from ~3 -> ~4 whilst migrating from DOTNETCORE|3.1 to DOTNET|6.0

ruslanss commented 2 years ago

Hi @remiX- ! yes try downgrading Scrutor nuget package to v4.1.0 if you're using it.

remiX- commented 2 years ago

Ah I'm not using it.

I had to resort to using Provider in the Add and create the instance

Something like this, even if I didn't need it builder.Services.AddSingleton<IValidator<WhateverCommand>>(sp => new NullValidator());

waynebrantley commented 1 year ago

@fabiocav @brettsam Wondering if this project is being depreciated? No changes since 2020. Who would we be able to get to update this type check to stop this issue - assuming this project is not dead?

brettsam commented 1 month ago

I'm fairly certain that this was fixed recently with this change in the host. The most current version of Functions v4 should now work (the issue above did not repro for me).

https://github.com/Azure/azure-functions-host/pull/10100

If you're able to reproduce this, please reactivate and ping me here.

brettsam commented 1 month ago

@fabiocav @brettsam Wondering if this project is being depreciated? No changes since 2020. Who would we be able to get to update this type check to stop this issue - assuming this project is not dead?

This is not deprecated and is still in use and supported, but it's a fairly thin wrapper, which means it rarely needs updating.