All Projects → khellang → Scrutor

khellang / Scrutor

Licence: mit
Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to Scrutor

netcore-wcf-service-proxy
Example of consuming multiple WCF services using a proxy implementation in a ASP.NET Core Web-application.
Stars: ✭ 42 (-97.81%)
Mutual labels:  dependency-injection, asp-net-core
Exceptionless.net
Exceptionless clients for the .NET platform
Stars: ✭ 362 (-81.1%)
Mutual labels:  hacktoberfest, asp-net-core
Tlint
Tighten linter for Laravel conventions
Stars: ✭ 274 (-85.69%)
Mutual labels:  conventions, hacktoberfest
Uragano
Uragano, A simple, high performance RPC library. Support load balancing, circuit breaker, fallback, caching, intercepting.
Stars: ✭ 28 (-98.54%)
Mutual labels:  dependency-injection, asp-net-core
Go Critic
The most opinionated Go source code linter for code audit.
Stars: ✭ 875 (-54.31%)
Mutual labels:  conventions, hacktoberfest
Asmin
Asmin is .NET CORE project infrastructure, to get a quick start on the project.
Stars: ✭ 89 (-95.35%)
Mutual labels:  dependency-injection, asp-net-core
Loopback Next
LoopBack makes it easy to build modern API applications that require complex integrations.
Stars: ✭ 3,972 (+107.42%)
Mutual labels:  hacktoberfest, dependency-injection
Di
PSR-11 compatible DI container and injector
Stars: ✭ 141 (-92.64%)
Mutual labels:  hacktoberfest, dependency-injection
Practical Aspnetcore
Practical samples of ASP.NET Core 2.1, 2.2, 3.1, 5.0 and 6.0 projects you can use. Readme contains explanations on all projects.
Stars: ✭ 6,199 (+223.71%)
Mutual labels:  hacktoberfest, asp-net-core
Professionalcsharp7
Code samples for the book Professional C# 7 and .NET Core 2.0 (with updates for 2.1), Wrox Press
Stars: ✭ 403 (-78.96%)
Mutual labels:  asp-net-core, dependency-injection
Inyector
Library to Implement Automatic dependency injection by Configuration over Scaned Assemblies
Stars: ✭ 13 (-99.32%)
Mutual labels:  dependency-injection, asp-net-core
Esp8266 deauther
Affordable WiFi hacking platform for testing and learning
Stars: ✭ 9,312 (+386.27%)
Mutual labels:  hacktoberfest, scanning
Signalr Client Swift
Swift SignalR Client for Asp.Net Core SignalR server
Stars: ✭ 213 (-88.88%)
Mutual labels:  hacktoberfest, asp-net-core
SocketHook
Socket hook is an injector based on EasyHook (win only) which redirect the traffic to your local server.
Stars: ✭ 38 (-98.02%)
Mutual labels:  dependency-injection, asp-net-core
Tsyringe
Lightweight dependency injection container for JavaScript/TypeScript
Stars: ✭ 2,761 (+44.18%)
Mutual labels:  hacktoberfest, dependency-injection
Umbraco Cms
The simple, flexible and friendly ASP.NET CMS used by more than 730.000 websites
Stars: ✭ 3,484 (+81.93%)
Mutual labels:  hacktoberfest, asp-net-core
Fluentvalidation.blazor
Fluent Validation-powered Blazor component for validating standard <EditForm> 🌌 ✅
Stars: ✭ 140 (-92.69%)
Mutual labels:  asp-net-core, dependency-injection
Rustscan
🤖 The Modern Port Scanner 🤖
Stars: ✭ 5,218 (+172.48%)
Mutual labels:  hacktoberfest, scanning
Vue.js With Asp.net Core Sample
This provides a sample code using vue.js running on ASP.NET Core
Stars: ✭ 44 (-97.7%)
Mutual labels:  asp-net-core, dependency-injection
Covid19 Notifier In
A sample Android App which notifies about COVID19 cases in 🇮🇳India after every 1 hour.
Stars: ✭ 116 (-93.94%)
Mutual labels:  hacktoberfest, dependency-injection

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>();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].