Home > database >  Migrating the asp.net core 3.1 to .net 6 error
Migrating the asp.net core 3.1 to .net 6 error

Time:08-25

I am migrating one of the projects from .net core 3.1 to .net 6. One of the project is not building and throwing this error.

ConfigureServicesExtensions.cs(62, 22): [CS1061] 'IServiceCollection' does not contain a definition for 'Decorate' and no accessible extension method 'Decorate' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

Please see the code example below where its failing after upgradte from .net 3.1 to 6.0

private static void RegisterCommandHandlers(IServiceCollection serviceCollection)
    {
        //Scruptor package : https://andrewlock.net/using-scrutor-to-automatically-register-your-services-with-the-asp-net-core-di-container/
        serviceCollection.Scan(scan => scan.FromAssemblyOf<ICommand>()
            .AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<>))
                .Where(_ => !_.IsGenericType))
            .AsImplementedInterfaces()
            .WithTransientLifetime());
        serviceCollection.Decorate(typeof(ICommandHandler<>), typeof(CommandHandlerLoggingDecorator<>));
    }

CodePudding user response:

If your packages are up to date then, you can try this :

  1. Clean and rebuild your Solution.

  2. Restart VS

CodePudding user response:

More a guess than an answer - AFAIK build DI had never exposed any Decorate method, the one I know comes from Scrutor library. Check if this library is installed.

UPD

Based on the added code - just install the Scrutor nuget.

  • Related