VirtoCommerce/vc-platform

Weird service collection self-registration

Closed this issue · 3 comments

Hi, is there any reason the platform registers the DI service collection in itself? This feels very weird...

@j-mok Good quetion, the code was added 5 years ago, I will review with the team and maybe find some reason.

This code is required to resolve IServiceCollection for ModuleInitializer class and then pass to modules. Without this line, DI throws exception. Maybe code can be improved but let's keep it as is.

Unhandled exception. System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Extensions.DependencyInjection.IServiceCollection' while attempting to activate 'VirtoCommerce.Platform.Modules.ModuleInitializer'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(ServiceIdentifier serviceIdentifier, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
...   
at VirtoCommerce.Platform.Modules.ServiceCollectionExtensions.AddModules(IServiceCollection services, IMvcBuilder mvcBuilder, Action`1 setupAction) in C:\Projects\git\VirtoCommerce\vc-platform\src\VirtoCommerce.Platform.Web\Extensions\ServiceCollectionExtensions.cs:line 33
...