Scrutor 6.1.0
dotnet add package Scrutor --version 6.1.0
NuGet\Install-Package Scrutor -Version 6.1.0
<PackageReference Include="Scrutor" Version="6.1.0" />
<PackageVersion Include="Scrutor" Version="6.1.0" />
<PackageReference Include="Scrutor" />
paket add Scrutor --version 6.1.0
#r "nuget: Scrutor, 6.1.0"
#:package Scrutor@6.1.0
#addin nuget:?package=Scrutor&version=6.1.0
#tool nuget:?package=Scrutor&version=6.1.0
Scrutor

Scrutor - I search or examine thoroughly; I probe, investigate or scrutinize
From scrūta, as the original sense of the verb was to search through trash. - https://en.wiktionary.org/wiki/scrutor
Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection
Installation
Install the Scrutor NuGet Package.
Package Manager Console
Install-Package Scrutor
.NET Core CLI
dotnet add package Scrutor
Usage
The library adds two extension methods to IServiceCollection
:
Scan
- This is the entry point to set up your assembly scanning.Decorate
- This method is used to decorate already registered services.
See Examples below for usage examples.
Examples
Scanning
var collection = new ServiceCollection();
collection.Scan(scan => scan
// We start out with all types in the assembly of ITransientService
.FromAssemblyOf<ITransientService>()
// AddClasses starts out with all public, non-abstract types in this assembly.
// These types are then filtered by the delegate passed to the method.
// In this case, we filter out only the classes that are assignable to ITransientService.
.AddClasses(classes => classes.AssignableTo<ITransientService>())
// We then specify what type we want to register these classes as.
// In this case, we want to register the types as all of its implemented interfaces.
// So if a type implements 3 interfaces; A, B, C, we'd end up with three separate registrations.
.AsImplementedInterfaces()
// And lastly, we specify the lifetime of these registrations.
.WithTransientLifetime()
// Here we start again, with a new full set of classes from the assembly above.
// This time, filtering out only the classes assignable to IScopedService.
.AddClasses(classes => classes.AssignableTo<IScopedService>())
// Now, we just want to register these types as a single interface, IScopedService.
.As<IScopedService>()
// And again, just specify the lifetime.
.WithScopedLifetime()
// Generic interfaces are also supported too, e.g. public interface IOpenGeneric<T>
.AddClasses(classes => classes.AssignableTo(typeof(IOpenGeneric<>)))
.AsImplementedInterfaces()
// And you scan generics with multiple type parameters too
// e.g. public interface IQueryHandler<TQuery, TResult>
.AddClasses(classes => classes.AssignableTo(typeof(IQueryHandler<,>)))
.AsImplementedInterfaces());
Scanning compiled view (UI) types
By default, Scrutor excludes compiler-generated types from the .AddClasses()
type filters. When loading views from a framework such as Avalonia UI, we need to opt in to compiler-generated types, like this:
.AddClasses(classes => classes
// Opt-in to compiler-generated types
.WithAttribute<CompilerGeneratedAttribute>()
// Optionally filter types to reduce number of service registrations.
.InNamespaces("MyApp.Desktop.Views")
.AssignableToAny(
typeof(Window),
typeof(UserControl)
)
.AsSelf()
.WithSingletonLifetime()
With some UI frameworks, these compiler-generated views implement quite a few interfaces, so unless you need them, it's probably best to register these classes .AsSelf()
; in other words, be very precise with your filters that accept compiler generated types.
Decoration
var collection = new ServiceCollection();
// First, add our service to the collection.
collection.AddSingleton<IDecoratedService, Decorated>();
// Then, decorate Decorated with the Decorator type.
collection.Decorate<IDecoratedService, Decorator>();
// Finally, decorate Decorator with the OtherDecorator type.
// As you can see, OtherDecorator requires a separate service, IService. We can get that from the provider argument.
collection.Decorate<IDecoratedService>((inner, provider) => new OtherDecorator(inner, provider.GetRequiredService<IService>()));
var serviceProvider = collection.BuildServiceProvider();
// When we resolve the IDecoratedService service, we'll get the following structure:
// OtherDecorator -> Decorator -> Decorated
var instance = serviceProvider.GetRequiredService<IDecoratedService>();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.DependencyModel (>= 8.0.2)
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.DependencyModel (>= 8.0.2)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.DependencyModel (>= 8.0.2)
NuGet packages (798)
Showing the top 5 NuGet packages that depend on Scrutor:
Package | Downloads |
---|---|
Swashbuckle.AspNetCore.Filters
Some additional useful filters for Swashbuckle.AspNetCore. This package replaces Swashbuckle.AspNetCore.Examples. |
|
Scrutor.AspNetCore
Dependency Injection Helper Package For .Net Core Apps |
|
Elsa.Core
Elsa is a set of workflow libraries and tools that enable lean and mean workflowing capabilities in any .NET Core application. This package contains the core of Elsa. Tip: reference the `Elsa` package instead of this one. |
|
Sitko.Core.App
Sitko.Core is a set of libraries to help build .NET Core applications fast |
|
Elsa
Bundles the most commonly-used packages when building an Elsa workflows application. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
6.1.0 | 478,566 | 6/3/2025 |
6.0.1 | 4,703,617 | 1/14/2025 |
6.0.0 | 81,246 | 1/13/2025 |
5.1.2 | 256,809 | 1/13/2025 |
5.0.3 | 51,679 | 12/23/2024 |
5.0.2 | 2,543,167 | 11/7/2024 |
5.0.1 | 2,791,987 | 9/26/2024 |
5.0.0 | 93,282 | 9/25/2024 |
4.2.2 | 28,887,595 | 3/27/2023 |
4.2.1 | 3,211,640 | 2/8/2023 |
4.2.0 | 15,433,763 | 5/31/2022 |
4.1.0 | 5,875,812 | 3/2/2022 |
4.0.0 | 1,842,528 | 1/28/2022 |
3.3.0 | 78,561,977 | 11/3/2020 |
3.2.2 | 5,118,489 | 8/25/2020 |
3.2.1 | 5,592,638 | 4/20/2020 |
3.2.0 | 2,243,099 | 2/6/2020 |
3.1.0 | 6,797,132 | 8/7/2019 |
3.0.3 | 28,112 | 8/7/2019 |
3.0.2 | 4,309,541 | 11/13/2018 |
3.0.1 | 21,600,009 | 8/30/2018 |
2.2.2 | 1,700,902 | 3/12/2018 |
2.2.1 | 86,350 | 3/1/2018 |
2.2.0 | 14,593 | 2/27/2018 |
2.1.2 | 372,443 | 8/28/2017 |
2.1.1 | 16,816 | 8/25/2017 |
2.1.0 | 9,169 | 8/23/2017 |
2.0.0 | 542,421 | 7/12/2017 |
2.0.0-rc2 | 8,009 | 5/1/2017 |
2.0.0-rc | 2,900 | 4/28/2017 |
2.0.0-beta | 2,564 | 4/10/2017 |
1.12.0 | 26,563 | 4/10/2017 |
1.11.0 | 3,298 | 4/7/2017 |
1.10.1 | 8,614 | 3/9/2017 |
1.10.0 | 182,752 | 9/12/2016 |
1.9.1 | 6,288 | 9/8/2016 |
1.9.0 | 2,893 | 9/8/2016 |
1.8.0 | 7,931 | 7/14/2016 |
1.7.0 | 11,480 | 5/29/2016 |
1.6.0 | 3,594 | 5/9/2016 |
1.5.0 | 3,060 | 4/22/2016 |
1.4.0 | 2,935 | 4/22/2016 |
1.3.2 | 2,971 | 4/8/2016 |
1.3.1 | 3,470 | 3/7/2016 |
1.3.0 | 3,018 | 2/29/2016 |
1.2.0 | 2,890 | 2/16/2016 |
1.1.1 | 3,571 | 11/25/2015 |
1.1.0 | 3,016 | 11/25/2015 |
1.0.0 | 23,460 | 11/14/2015 |