khellang/Scrutor sits at 4.3k stars on GitHub, written primarily in C#. Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
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>();
Sponsors
Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of Scrutor.
The most recent commit recorded on khellang/Scrutor was 9 months ago, based on the GitHub push timestamp. The repository has 279 forks — one of the better signals of community interest.
How many stars does khellang/Scrutor have?
khellang/Scrutor has 4.3k GitHub stars — refresh the page for the live number, or check github.com/khellang/Scrutor. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is khellang/Scrutor written in?
khellang/Scrutor is written primarily in C#. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is khellang/Scrutor associated with?
GitHub's repository topics for khellang/Scrutor: "asp-net-core", "assembly-scanning", "convention-registration", "conventions", "decoration", "decoration-extensions", "dependency-injection", "hacktoberfest", "scanning", "scrutor". TopGit's editorial category is open-source.
Where do I read more about khellang/Scrutor?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/khellang/Scrutor is the definitive source.
Read full README in the tab above.
Is Scrutor worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of Scrutor.