{"id":13431182,"url":"https://github.com/khellang/Scrutor","last_synced_at":"2025-03-16T11:31:10.726Z","repository":{"id":2288995,"uuid":"46156101","full_name":"khellang/Scrutor","owner":"khellang","description":"Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection","archived":false,"fork":false,"pushed_at":"2025-01-14T13:45:37.000Z","size":367,"stargazers_count":3792,"open_issues_count":43,"forks_count":246,"subscribers_count":61,"default_branch":"master","last_synced_at":"2025-03-12T04:01:25.688Z","etag":null,"topics":["asp-net-core","assembly-scanning","convention-registration","conventions","decoration","decoration-extensions","dependency-injection","hacktoberfest","scanning","scrutor"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khellang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"khellang","tidelift":"nuget/scrutor","buy_me_a_coffee":"khellang"}},"created_at":"2015-11-14T01:26:41.000Z","updated_at":"2025-03-10T18:38:44.000Z","dependencies_parsed_at":"2023-11-15T16:27:47.381Z","dependency_job_id":"5180753d-8101-4323-85e4-0b646387351b","html_url":"https://github.com/khellang/Scrutor","commit_stats":{"total_commits":333,"total_committers":38,"mean_commits":8.763157894736842,"dds":0.3573573573573574,"last_synced_commit":"14a61ccb6adaa928f2c0549fa61f16e2b8c63f68"},"previous_names":["khellang/dependencyinjection.scanning"],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khellang%2FScrutor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khellang%2FScrutor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khellang%2FScrutor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khellang%2FScrutor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khellang","download_url":"https://codeload.github.com/khellang/Scrutor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809851,"owners_count":20351407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-core","assembly-scanning","convention-registration","conventions","decoration","decoration-extensions","dependency-injection","hacktoberfest","scanning","scrutor"],"created_at":"2024-07-31T02:01:01.124Z","updated_at":"2025-03-16T11:31:10.420Z","avatar_url":"https://github.com/khellang.png","language":"C#","readme":"# Scrutor [![Build status](https://ci.appveyor.com/api/projects/status/j00uyvqnm54rdlkb?svg=true)](https://ci.appveyor.com/project/khellang/scrutor) [![NuGet Package](https://img.shields.io/nuget/v/Scrutor.svg)](https://www.nuget.org/packages/Scrutor)\n\n\u003e Scrutor - I search or examine thoroughly; I probe, investigate or scrutinize  \n\u003e From scrūta, as the original sense of the verb was to search through trash. - https://en.wiktionary.org/wiki/scrutor\n\nAssembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection\n\n## Installation\n\nInstall the [Scrutor NuGet Package](https://www.nuget.org/packages/Scrutor).\n\n### Package Manager Console\n\n```\nInstall-Package Scrutor\n```\n\n### .NET Core CLI\n\n```\ndotnet add package Scrutor\n```\n\n## Usage\n\nThe library adds two extension methods to `IServiceCollection`:\n\n* `Scan` - This is the entry point to set up your assembly scanning.\n* `Decorate` - This method is used to decorate already registered services.\n\nSee **Examples** below for usage examples.\n\n## Examples\n\n### Scanning\n\n```csharp\nvar collection = new ServiceCollection();\n\ncollection.Scan(scan =\u003e scan\n     // We start out with all types in the assembly of ITransientService\n    .FromAssemblyOf\u003cITransientService\u003e()\n        // AddClasses starts out with all public, non-abstract types in this assembly.\n        // These types are then filtered by the delegate passed to the method.\n        // In this case, we filter out only the classes that are assignable to ITransientService.\n        .AddClasses(classes =\u003e classes.AssignableTo\u003cITransientService\u003e())\n            // We then specify what type we want to register these classes as.\n            // In this case, we want to register the types as all of its implemented interfaces.\n            // So if a type implements 3 interfaces; A, B, C, we'd end up with three separate registrations.\n            .AsImplementedInterfaces()\n            // And lastly, we specify the lifetime of these registrations.\n            .WithTransientLifetime()\n        // Here we start again, with a new full set of classes from the assembly above.\n        // This time, filtering out only the classes assignable to IScopedService.\n        .AddClasses(classes =\u003e classes.AssignableTo\u003cIScopedService\u003e())\n            // Now, we just want to register these types as a single interface, IScopedService.\n            .As\u003cIScopedService\u003e()\n            // And again, just specify the lifetime.\n            .WithScopedLifetime()\n        // Generic interfaces are also supported too, e.g. public interface IOpenGeneric\u003cT\u003e \n        .AddClasses(classes =\u003e classes.AssignableTo(typeof(IOpenGeneric\u003c\u003e)))\n            .AsImplementedInterfaces()\n        // And you scan generics with multiple type parameters too\n        // e.g. public interface IQueryHandler\u003cTQuery, TResult\u003e\n        .AddClasses(classes =\u003e classes.AssignableTo(typeof(IQueryHandler\u003c,\u003e)))\n            .AsImplementedInterfaces());\n```\n\n### Decoration\n\n```csharp\nvar collection = new ServiceCollection();\n\n// First, add our service to the collection.\ncollection.AddSingleton\u003cIDecoratedService, Decorated\u003e();\n\n// Then, decorate Decorated with the Decorator type.\ncollection.Decorate\u003cIDecoratedService, Decorator\u003e();\n\n// Finally, decorate Decorator with the OtherDecorator type.\n// As you can see, OtherDecorator requires a separate service, IService. We can get that from the provider argument.\ncollection.Decorate\u003cIDecoratedService\u003e((inner, provider) =\u003e new OtherDecorator(inner, provider.GetRequiredService\u003cIService\u003e()));\n\nvar serviceProvider = collection.BuildServiceProvider();\n\n// When we resolve the IDecoratedService service, we'll get the following structure:\n// OtherDecorator -\u003e Decorator -\u003e Decorated\nvar instance = serviceProvider.GetRequiredService\u003cIDecoratedService\u003e();\n```\n","funding_links":["https://github.com/sponsors/khellang","https://tidelift.com/funding/github/nuget/scrutor","https://buymeacoffee.com/khellang"],"categories":["Frameworks, Libraries and Tools","C\\#","hacktoberfest","C#","框架, 库和工具","Dependency Injection","Runtime dependency injection","IoC","C# #","🗒️ Cheatsheets"],"sub_categories":["Misc","大杂烩","GUI - other","📦 Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhellang%2FScrutor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhellang%2FScrutor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhellang%2FScrutor/lists"}