ServiceComposer / ServiceComposer.AspNetCore

🧩 ServiceComposer, a ViewModel Composition API Gateway
https://milestone.topics.it/categories/view-model-composition
Apache License 2.0
75 stars 11 forks source link

EndpointScopedViewModelFactory not found #520

Closed peterhut closed 1 year ago

peterhut commented 1 year ago

I encountered an issue when trying out an EndpointScopedViewModelFactory and kept getting the error 'Cannot convert view model to XyzViewModel. Make sure a custom view model factory is registered and that the created view model is of type XyzViewModel.'

Looking at the unit test Get_with_2_handlers_using_endpoint_scoped_view_model_factory I noticed it registered the ViewModelFactory explicitly using options.RegisterEndpointScopedViewModelFactory. Trying that it fixed the issue.

Is it necessary to always register it explicitly or is the automatic registration in ViewModelCompositionOptions for IEndpointScopedViewModelFactory not doing the right thing?

mauroservienti commented 1 year ago

Thanks for raising this, @peterhut. That might be a bug. In theory, it should be automatic.

Tests use explicit registrations to avoid assembly scanning that would load all types from all test classes, which is a problem. There are a few tests testing assembly scanning, and I guess that scenario is not covered.

I'll look into it.

mauroservienti commented 1 year ago

I can reproduce the issue in #522

mauroservienti commented 1 year ago

Fixed. I'll release it as 2.0.1.

mauroservienti commented 1 year ago

The package is on NuGet (indexing is ongoing)