Scrutor 6.0.1

dotnet add package Scrutor --version 6.0.1
                    
NuGet\Install-Package Scrutor -Version 6.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Scrutor" Version="6.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Scrutor" Version="6.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Scrutor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Scrutor --version 6.0.1
                    
#r "nuget: Scrutor, 6.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Scrutor&version=6.0.1
                    
Install Scrutor as a Cake Addin
#tool nuget:?package=Scrutor&version=6.0.1
                    
Install Scrutor as a Cake Tool

Scrutor Build status NuGet Package

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());

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 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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (759)

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

Sitko.Core.App

Sitko.Core is a set of libraries to help build .NET Core applications fast

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.

Elsa

Bundles the most commonly-used packages when building an Elsa workflows application.

GitHub repositories (83)

Showing the top 20 popular GitHub repositories that depend on Scrutor:

Repository Stars
RayWangQvQ/BiliBiliToolPro
B 站(bilibili)自动任务工具,支持docker、青龙、k8s等多种部署方式。敏感肌也能用。
elsa-workflows/elsa-core
A .NET workflows library
kurrent-io/EventStore
EventStoreDB, the event-native database. Designed for Event Sourcing, Event-Driven, and Microservices architectures
MapsterMapper/Mapster
A fast, fun and stimulating object to object Mapper
ivanpaulovich/clean-architecture-manga
:cyclone: Clean Architecture with .NET6, C#10 and React+Redux. Use cases as central organizing structure, completely testable, decoupled from frameworks
oskardudycz/EventSourcing.NetCore
Examples and Tutorials of Event Sourcing in .NET
aspnetrun/run-aspnetcore-microservices
Microservices on .NET platforms used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12
vietnam-devs/coolstore-microservices
A full-stack .NET microservices build on Dapr and Tye
microsoft/sbom-tool
The SBOM tool is a highly scalable and enterprise ready tool to create SPDX 2.2 compatible SBOMs for any variety of artifacts.
thangchung/clean-architecture-dotnet
🕸 Yet Another .NET Clean Architecture, but for Microservices project. It uses Minimal Clean Architecture with DDD-lite, CQRS-lite, and just enough Cloud-native patterns apply on the simple eCommerce sample and run on Tye with Dapr extension 🍻
VirtoCommerce/vc-platform
Virto Commerce B2B Innovation Platform
grandnode/grandnode2
E-commerce platform built with ASP.NET Core using MongoDB for NoSQL storage
lookup-foundation/RevitLookup
Interactive Revit RFA and RVT project database exploration tool to view and navigate BIM element parameters, properties and relationships.
matthewrenze/clean-architecture-demo
A sample app for my online course "Clean Architecture: Patterns, Practices, and Principles"
gautema/CQRSlite
A lightweight framework to help creating CQRS and Eventsourcing applications in C#
meysamhadeli/monolith-to-cloud-architecture
A practical architecture styles for migrating from monolith to modern cloud native application with the latest technologies and architectures like Vertical Slice Architecture, Event Sourcing, CQRS, DDD, gRpc, MongoDB, RabbitMq, and Masstransit in .Net 9.
snatch-dev/Convey
A simple recipe for .NET Core microservices.
roflmuffin/CounterStrikeSharp
CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
mehdihadeli/food-delivery-microservices
🍔 A practical and imaginary food delivery microservices, built with .Net 9, MassTransit, Domain-Driven Design, CQRS, Vertical Slice Architecture, Event-Driven Architecture, and the latest technologies.
Version Downloads Last updated
6.0.1 1,459,124 1/14/2025
6.0.0 53,789 1/13/2025
5.1.2 89,220 1/13/2025
5.0.3 24,040 12/23/2024
5.0.2 1,824,168 11/7/2024
5.0.1 1,838,913 9/26/2024
5.0.0 72,803 9/25/2024
4.2.2 25,573,095 3/27/2023
4.2.1 3,082,712 2/8/2023
4.2.0 14,734,446 5/31/2022
4.1.0 5,642,456 3/2/2022
4.0.0 1,754,225 1/28/2022
3.3.0 71,290,619 11/3/2020
3.2.2 4,983,680 8/25/2020
3.2.1 5,515,890 4/20/2020
3.2.0 2,211,718 2/6/2020
3.1.0 6,658,146 8/7/2019
3.0.3 26,051 8/7/2019
3.0.2 4,258,163 11/13/2018
3.0.1 21,189,095 8/30/2018
2.2.2 1,665,531 3/12/2018
2.2.1 84,954 3/1/2018
2.2.0 14,338 2/27/2018
2.1.2 358,280 8/28/2017
2.1.1 16,587 8/25/2017
2.1.0 8,996 8/23/2017
2.0.0 495,273 7/12/2017
2.0.0-rc2 7,890 5/1/2017
2.0.0-rc 2,772 4/28/2017
2.0.0-beta 2,434 4/10/2017
1.12.0 26,388 4/10/2017
1.11.0 3,160 4/7/2017
1.10.1 8,480 3/9/2017
1.10.0 181,514 9/12/2016
1.9.1 6,152 9/8/2016
1.9.0 2,757 9/8/2016
1.8.0 7,794 7/14/2016
1.7.0 11,337 5/29/2016
1.6.0 3,460 5/9/2016
1.5.0 2,929 4/22/2016
1.4.0 2,799 4/22/2016
1.3.2 2,833 4/8/2016
1.3.1 3,325 3/7/2016
1.3.0 2,877 2/29/2016
1.2.0 2,757 2/16/2016
1.1.1 3,377 11/25/2015
1.1.0 2,865 11/25/2015
1.0.0 19,930 11/14/2015