{"id":19899507,"url":"https://github.com/brightercommand/darker","last_synced_at":"2025-05-16T12:10:22.988Z","repository":{"id":10064074,"uuid":"64324829","full_name":"BrighterCommand/Darker","owner":"BrighterCommand","description":"The query-side counterpart of Brighter","archived":false,"fork":false,"pushed_at":"2024-07-09T10:01:14.000Z","size":442,"stargazers_count":205,"open_issues_count":11,"forks_count":24,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-02T03:16:25.679Z","etag":null,"topics":["brighter","darker","dotnet-core","handlers","query"],"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/BrighterCommand.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-27T16:33:03.000Z","updated_at":"2025-03-28T17:30:47.000Z","dependencies_parsed_at":"2024-03-15T16:24:54.255Z","dependency_job_id":"b7c32649-3eae-4ce6-9d63-f19a4c449936","html_url":"https://github.com/BrighterCommand/Darker","commit_stats":{"total_commits":238,"total_committers":14,"mean_commits":17.0,"dds":0.5294117647058824,"last_synced_commit":"1a7b8851d6aed8f5c1b2dd5e73c96d1ab4b19488"},"previous_names":["dstockhammer/darker"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrighterCommand%2FDarker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrighterCommand%2FDarker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrighterCommand%2FDarker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrighterCommand%2FDarker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrighterCommand","download_url":"https://codeload.github.com/BrighterCommand/Darker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980836,"owners_count":21027808,"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":["brighter","darker","dotnet-core","handlers","query"],"created_at":"2024-11-12T20:08:55.156Z","updated_at":"2025-04-09T05:07:28.434Z","avatar_url":"https://github.com/BrighterCommand.png","language":"C#","readme":"# Darker\nThe query-side counterpart of [Brighter](https://github.com/BrighterCommand/Paramore.Brighter).\n\n![.NET Core](https://github.com/BrighterCommand/Darker/workflows/.NET%20Core/badge.svg)\n[![NuGet](https://img.shields.io/nuget/v/Paramore.Darker.svg)](https://www.nuget.org/packages/Paramore.Darker)\n\n## Usage with ASP.NET Core\nIn your `ConfigureServices` method, use `AddDarker` to add Darker to the container.\nASP.NET Core integration is provided by the [Paramore.Darker.AspNetCore](https://www.nuget.org/packages/Paramore.Darker.AspNetCore) package.\n\n```csharp\n// This method gets called by the runtime. Use this method to add services to the container.\npublic void ConfigureServices(IServiceCollection services)\n{\n    // Add Darker and some extensions.\n    services.AddDarker()\n        .AddHandlersFromAssemblies(typeof(GetPeopleQueryHandler).Assembly)\n        .AddJsonQueryLogging()\n        .AddDefaultPolicies();\n\n    // Add framework services.\n    services.AddMvc();\n}\n```\n**WARNING** if you are using EFCore the DBContext DI Lifetime is scoped, for Darker to play nicely with EFCore and DI the QueryProcessor must also be registration as Scoped\n```csharp\n services.AddDarker(options =\u003e\n                {\n                    //EFCore by default registers Context as scoped, which forces the QueryProcessorLifetime to also be scoped\n                    options.QueryProcessorLifetime = ServiceLifetime.Scoped;\n                })\n```\n\nThis example uses the request logging integration provided by [Paramore.Darker.QueryLogging](https://www.nuget.org/packages/Paramore.Darker.QueryLogging)\nand policy integration provided by [Paramore.Darker.Policies](https://www.nuget.org/packages/Paramore.Darker.Policies).\nHave a look at the [Startup.ConfigureServices](https://github.com/BrighterCommand/Darker/blob/master/samples/SampleApi/Startup.cs) method\nin the [SampleApi](https://github.com/BrighterCommand/Darker/tree/master/samples/SampleApi) project for more examples on how to use the integrations.\n\nInject `IQueryProcessor` and call `Execute` or `ExecuteAsync` to dispatch your query to the registered query handler.\n\n```csharp\nusing Paramore.Darker;\nusing Microsoft.AspNetCore.Mvc;\nusing System.Threading;\nusing System.Threading.Tasks;\n\npublic class FooController : ControllerBase\n{\n    private readonly IQueryProcessor _queryProcessor;\n\n    public FooController(IQueryProcessor queryProcessor)\n    {\n        _queryProcessor = queryProcessor;\n    }\n\n    public async Task\u003cIActionResult\u003e Get(CancellationToken cancellationToken = default(CancellationToken))\n    {\n        var query = new GetFoo(42);\n        var result = await _queryProcessor.ExecuteAsync(query, cancellationToken);\n        return Ok(result);\n    }\n}\n```\n\n```csharp\nusing Paramore.Darker;\n\npublic sealed class GetFoo : IQuery\u003cstring\u003e\n{\n    public int Number { get; }\n\n    public GetFoo(int number)\n    {\n        Number = number;\n    }\n}\n```\n\nImplement either `QueryHandler\u003c,\u003e` or `QueryHandlerAsync\u003c,\u003e` depending on whether you wish to execute your queries synchronously or asynchronously.\nFor most control, you can also implement `IQueryHandler\u003c,\u003e` directly.\n\n```csharp\nusing Paramore.Darker;\nusing Paramore.Darker.Attributes;\nusing Paramore.Darker.Policies;\nusing Paramore.Darker.QueryLogging;\nusing System.Threading;\nusing System.Threading.Tasks;\n\npublic sealed class GetFooHandler : QueryHandlerAsync\u003cGetFoo, string\u003e\n{\n    [QueryLogging(1)]\n    [FallbackPolicy(2)]\n    [RetryableQuery(3)]\n    public override async Task\u003cstring\u003e ExecuteAsync(GetFoo query, CancellationToken cancellationToken = default(CancellationToken))\n    {\n        return await FetchFooForNumber(query.Number, cancellationToken);\n    }\n}\n```\n\n## Usage without ASP.NET\nRegister your queries and handlers with `QueryHandlerRegistry` and use `QueryProcessorBuilder` to configure and build a `IQueryProcessor`.\n\n```csharp\nvar registry = new QueryHandlerRegistry();\nregistry.Register\u003cGetFoo, string, GetFooHandler\u003e();\n\nIQueryProcessor queryProcessor = QueryProcessorBuilder.With()\n    .Handlers(registry, Activator.CreateInstance, t =\u003e {}, Activator.CreateInstance)\n    .InMemoryQueryContextFactory()\n    .Build();\n```\n\nInstead of `Activator.CreateInstance`, you can pass any factory `Func\u003cType, object\u003e` to constuct handlers and decorator.\nIntegrations with some DI frameworks are available, for example [SimpleInjector](https://simpleinjector.org), as provided by the [Paramore.Darker.SimpleInjector](https://www.nuget.org/packages/Paramore.Darker.SimpleInjector) package:\n\n```csharp\nvar container = new Container();\n\nvar queryProcessor = QueryProcessorBuilder.With()\n    .SimpleInjectoHandlers(container, opts =\u003e\n        opts.WithQueriesAndHandlersFromAssembly(typeof(GetPeopleQuery).Assembly))\n    .InMemoryQueryContextFactory()\n    .Build();\n\ncontainer.Register\u003cIQueryProcessor\u003e(queryProcessor);\n```\n\nIn this case you don't need to manually register queries or handlers as the integration allows scanning assemblies for matching types.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightercommand%2Fdarker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrightercommand%2Fdarker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightercommand%2Fdarker/lists"}