{"id":18246639,"url":"https://github.com/datvm/servicesharp","last_synced_at":"2026-04-07T11:31:21.432Z","repository":{"id":143659133,"uuid":"140016575","full_name":"datvm/ServiceSharp","owner":"datvm","description":"ServiceSharp is a tiny utility for registering services in .NET DI using [Attribute] or Interface","archived":false,"fork":false,"pushed_at":"2025-06-24T04:39:02.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-24T09:15:34.564Z","etag":null,"topics":[],"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/datvm.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MD","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}},"created_at":"2018-07-06T18:07:43.000Z","updated_at":"2025-06-24T04:39:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"b54da092-9f6f-4b70-9304-9dec198f7474","html_url":"https://github.com/datvm/ServiceSharp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/datvm/ServiceSharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FServiceSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FServiceSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FServiceSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FServiceSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datvm","download_url":"https://codeload.github.com/datvm/ServiceSharp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FServiceSharp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268655127,"owners_count":24285128,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-05T09:27:06.748Z","updated_at":"2026-04-07T11:31:21.397Z","avatar_url":"https://github.com/datvm.png","language":"C#","readme":"# ServiceSharp\n\nServiceSharp v2.1.0 is released with .NET Standard 2.1 support and new features!  \nv2.0.0 was released with .NET 6 and rewritten from scratch! You no longer need the ASP.NET Core specific package as well.\n\nServiceSharp is a tiny utility for registering services in .NET Dependency Injection (DI) using **`[Attribute]`**, **`[SelfService]`**, or `Interface`:\n\n## Declare using Attributes\n\n```cs\n[Service(typeof(ITestAttr1))] // Explicit declaration\nclass ImplAttr1 : DefaultImplementation, ITestAttr1 { }\n\n[Ignore]\ninterface IShouldIgnore {} // Ignore this interface unless explicitly declared\n\n[Service] // Automatically register all implemented interfaces\nclass ImplAttr23 : \n    ITestAttr2, ITestAttr3,\n    IShouldIgnore // Ignored unless explicitly registered\n{ }\n\n[Service(typeof(ITestAttr4)), // Multiple explicit declarations\n Service(typeof(ITestAttr5))] // Multiple explicit declarations\nclass ImplAttr456 : DefaultImplementation, ITestAttr4, ITestAttr5, ITestAttr6 { }\n\n[Service(Lifetime = ServiceLifetime.Scoped)] // Lifetime can be specified\nclass ImplScoped : ITestAttrScoped { }\n\n[Service(Lifetime = ServiceLifetime.Transient)]\nclass ImplTransient : ITestAttrTransient { }\n\n[Service(Lifetime = ServiceLifetime.Singleton)]\nclass ImplSingleton : ITestAttrSingleton { }\n\n[SelfService] // Register the class as itself (not by interface)\nclass SelfServiceClass { }\n\n[SelfService] // Register as itself, not by interface\nclass ImplSelfServiceWithInterface : ISelfServiceInterface { }\n```\n\n## Declare using Interfaces\n\n```cs\nclass ImplInterface1 :\n    ITestInterface1,\n    ITestInterface2,\n    ITestInterface3,           // This service is not registered\n    IService\u003cITestInterface1\u003e, // Explicit declaration\n    IService\u003cITestInterface2\u003e  // Explicit declaration\n{ }\n\n[Ignore]\ninterface IShouldIgnore {} // Ignore this interface unless explicitly declared\n\n// Use Interface declaration for all implemented interfaces\nclass ImplInterface23 : \n    IService, // Automatically register all implemented interfaces\n    ITestInterface2,\n    ITestInterface3,\n    IShouldIgnore // Ignored unless explicitly registered\n{ }\n\n[Ignore] // Do not register this class though it implements IService interface\nclass ImplInterface3 : \n    ITestInterface3,\n    IService\n{ }\n```\n\n\u003e **Note**  \n\u003e The lifetime of the service cannot be specified using interface declaration. It uses the value from options instead. The default value is `Scoped`.\n\n\u003e **New in 2.1.0**  \n\u003e Use `[SelfService]` to register a class as itself (not by interface). If the class also implements interfaces, those interfaces are not registered unless you use `[Service]` or interface-based registration.\n\n# Installation\n\nYou can install from [Nuget Package](https://www.nuget.org/packages/ServiceSharp/):\n\n```ps\nInstall-Package ServiceSharp\n```\n\n\u003e **Note**  \n\u003e The old package for [ASP.NET Core](https://www.nuget.org/packages/ServiceSharp.AspNetCore/) is now deprecated. You don't need it anymore.\n\n# Usage\n\nUse `AddServices` to register all the declared services in the Assembly:\n\n```\nservices.AddServices();\n```\n\nYou can also optionally specify a few options:\n\n```cs\nservices.AddServices(options =\u003e {\n    // Change scanning Assembly,\n    // the default is Assembly.GetCallingAssembly() which should be your own code\n    options.Assembly = Assembly.GetExecutingAssembly();\n\n    // Add more assemblies to be scanned in case you have multiple assemblies\n    options.AdditionalAssemblies.Add(GetMyAssembly());\n\n    // Set the default Lifetime for the services if not specified by Attribute declaration\n    // The default value is Scoped\n    options.Lifetime = ServiceLifetime.Scoped;\n\n    // You can also make and specify your own scanner\n    options.TypeScanner = new MyTypeScanner();\n});```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatvm%2Fservicesharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatvm%2Fservicesharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatvm%2Fservicesharp/lists"}