lillo42 / webthing-csharp

.NET implementation of a Web Thing server
Apache License 2.0
23 stars 6 forks source link

Dependency Injection error 'Cannot consume scoped service from singleton' on startup #55

Closed michaelkargl closed 4 years ago

michaelkargl commented 4 years ago

Hello,

Yesterday I found this awesome project and tried setting it up for a project at work. Unfortunately when starting the 'SingleThing' sample application (and also ours) it threw an exception:

AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Mozilla.IoT.WebThing.Factories.IThingContextFactory Lifetime: Transient ImplementationType: Mozilla.IoT.WebThing.Factories.ThingContextFactory': Cannot consume scoped service 'Mozilla.IoT.WebThing.Factories.IJsonSchemaValidationFactory' from singleton 'Mozilla.IoT.WebThing.Factories.IPropertyFactory'.) (Error while validating the service descriptor 'ServiceType: Mozilla.IoT.WebThing.Builders.IPropertyBuilder Lifetime: Transient ImplementationType: Mozilla.IoT.WebThing.Builders.PropertyBuilder': Cannot consume scoped service 'Mozilla.IoT.WebThing.Factories.IJsonSchemaValidationFactory' from singleton 'Mozilla.IoT.WebThing.Factories.IPropertyFactory'.) (Error while validating the service descriptor 'ServiceType: Mozilla.IoT.WebThing.Factories.IPropertyFactory Lifetime: Singleton ImplementationType: Mozilla.IoT.WebThing.Factories.PropertyFactory': Cannot consume scoped service 'Mozilla.IoT.WebThing.Factories.IJsonSchemaValidationFactory' from singleton 'Mozilla.IoT.WebThing.Factories.IPropertyFactory'.)

Installed versions: dotnet --version > 3.1.301 Mozilla.IoT.WebThing > 2.0.0 Project target version > .NET Core 3.1

Did you come across this error on your journey? I'll continue searching :) Thanks for the cool project!

lillo42 commented 4 years ago

@michaelkargl Thank you, I've find the bug and as soon as possible I will generate a new release :)

Did you come across this error on your journey?

It's weird, because when I'm using the project directory it worked but when I change to use the nuget I got this error too. Anyway it's a error on DI lifetime

michaelkargl commented 4 years ago

Thanks a lot! Updated just now and everything worked great 👍