'IServiceCollection' does not contain a definition for 'Scan'
See original GitHub issueIn a .NET Core App I’m facing this error:
Error CS1061 'IServiceCollection' does not contain a definition for 'Scan' and no extension method 'Scan' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
The code of ConfigureServices
looks like this:
services.Scan(scan => scan
.FromAssemblies(typeof(MaterialCommandHandler).GetTypeInfo().Assembly)
.AddClasses(classes => classes.Where(x => {
var allInterfaces = x.GetInterfaces();
return
allInterfaces.Any(y => y.GetTypeInfo().IsGenericType && y.GetTypeInfo().GetGenericTypeDefinition() == typeof(IHandler<>)) ||
allInterfaces.Any(y => y.GetTypeInfo().IsGenericType && y.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICancellableHandler<>));
}))
.AsSelf()
.WithTransientLifetime()
);
I’m using Scrutor 2.0.0.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
.net - 'IServiceCollection' does not contain a definition for ' ...
I'm using .NET 6 in Program.cs: builder.Services.AddMediatR(Assembly.GetExecutingAssembly());. I get: 'IServiceCollection ...
Read more >'IServiceCollection' does not contain a definition for 'Scan'
In a .NET Core App I'm facing this error: Error CS1061 'IServiceCollection' does not contain a definition for 'Scan' and no extension method ......
Read more >Fix: IServiceCollection does not contain a definition ... - YouTube
Fix: IServiceCollection does not contain a definition for 'AddDefaultIdentity' and no accessible extension method 'AddDefaultIdentity' ...
Read more >IServiceCollection Interface
Specifies the contract for a collection of service descriptors.
Read more >IServiceCollection doesn't contain a definition of ...
Issue resolution for error IServiceCollection doesn't contain a definition of AddSwaggerGen in ASP.NET API after adding the Swashbuckle NuGet package.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Glad you figured it out! BTW,
FromAssemblies
can be replaced withFromAssemblyOf<MaterialCommandHandler>
and theWhere
clause could be replaced withAssignableToAny(typeof(IHandler<>), typeof(ICancellableHandler<>))
. I just typed this on my phone, so I can’t guarantee that it compiles, but you get the gist 😉You mean scrutor