{"id":15409194,"url":"https://github.com/devlead/cake.bridge.dependencyinjection","last_synced_at":"2026-03-02T09:05:06.065Z","repository":{"id":62601349,"uuid":"327531576","full_name":"devlead/Cake.Bridge.DependencyInjection","owner":"devlead","description":"Provides helpers for providing Cake context using Microsoft DependencyInjection, letting you use Cake Core/Common/Addins abstractions and aliases.","archived":false,"fork":false,"pushed_at":"2025-04-09T19:39:25.000Z","size":105,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-09T20:36:06.850Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/devlead.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":"devlead"}},"created_at":"2021-01-07T07:07:00.000Z","updated_at":"2025-04-09T19:39:29.000Z","dependencies_parsed_at":"2024-10-01T16:38:20.485Z","dependency_job_id":"2eb5ffce-5d30-4144-a7dd-a75c5eb14f7f","html_url":"https://github.com/devlead/Cake.Bridge.DependencyInjection","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.05128205128205132,"last_synced_commit":"016d735f5c85f75a22deea3e6ef1922455b7e528"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlead%2FCake.Bridge.DependencyInjection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlead%2FCake.Bridge.DependencyInjection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlead%2FCake.Bridge.DependencyInjection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlead%2FCake.Bridge.DependencyInjection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlead","download_url":"https://codeload.github.com/devlead/Cake.Bridge.DependencyInjection/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249598382,"owners_count":21297464,"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":[],"created_at":"2024-10-01T16:38:13.742Z","updated_at":"2026-03-02T09:05:06.028Z","avatar_url":"https://github.com/devlead.png","language":"C#","readme":"# Cake Bridge DependencyInjection\n\nProvides helpers for providing Cake context using Microsoft DependencyInjection, letting you use Cake Core/Common/Addins abstractions and aliases.\n\n## Usage\n\n### Obtain\n\nThe assembly is published at [nuget.org/packages/Cake.Bridge.DependencyInjection](https://www.nuget.org/packages/Cake.Bridge.DependencyInjection).\n\n#### .NET CLI\n\n```bash\ndotnet add package Cake.Bridge.DependencyInjection\n```\n\n#### PackageReference\n```xml\n\u003cPackageReference Include=\"Cake.Bridge.DependencyInjection\" Version=\"0.4.0\" /\u003e\n```\n\n### Register\n\n```csharp\nusing Cake.Bridge.DependencyInjection;\n...\nserviceCollection\n    .AddCakeCore();\n```\n\n### Use\n\nOnce registered you can now via dependency injection access majority [Cake.Core](https://cakebuild.net/api/Cake.Core/#InterfaceTypes) interfaces with ease, i.e:\n\n| Type         | Description |\n|--------------|-------------|\n| [ICakeContext](https://cakebuild.net/api/Cake.Core/ICakeContext/) | Gives access to Cake built-in and addin aliases, and most Cake abstractions. |\n| [IScriptHost](https://cakebuild.net/api/Cake.Core.Scripting/IScriptHost/) | Gives access to script runner. |\n| [ICakeLog](https://cakebuild.net/api/Cake.Core.Diagnostics/ICakeLog/) | Cake logging implementation. |\n| [IFileSystem](https://cakebuild.net/api/Cake.Core.IO/IFileSystem/) | Cake file system abstraction. |\n\n### Example\n\n```csharp\nvar serviceCollection = new ServiceCollection()\n    .AddCakeCore();\n\nvar serviceProvider = serviceCollection.BuildServiceProvider();\n\nvar scriptHost = serviceProvider.GetRequiredService\u003cIScriptHost\u003e();\n\nscriptHost.Task(\"Hello\")\n    .Does(ctx =\u003e ctx.Information(\"Hello\"));\n\nscriptHost.Task(\"World\")\n    .IsDependentOn(\"Hello\")\n    .Does(ctx =\u003e ctx.Information(\"World\"));\n\nawait scriptHost.RunTargetAsync(\"World\");\n```\n\nwill output\n\n```powershell\n========================================\nHello\n========================================\nHello\n\n========================================\nWorld\n========================================\nWorld\n\nTask                          Duration\n--------------------------------------------------\nHello                         00:00:00.0226275\nWorld                         00:00:00.0002682\n--------------------------------------------------\nTotal:                        00:00:00.0228957\n```\n\nA full example console application using [Spectre.Console](https://www.nuget.org/packages/Spectre.Console) demonstrating usage of both [ICakeContext](https://cakebuild.net/api/Cake.Core/ICakeContext/) and [IScriptHost](https://cakebuild.net/api/Cake.Core.Scripting/IScriptHost/) can be found in this repository at [src/Cake.Bridge.DependencyInjection.Example](src/Cake.Bridge.DependencyInjection.Example).\n\n## Testing\n\nCake.Bridge.DependencyInjection.Testing provides mock implementations of Cake Core interfaces for in-memory unit tests with minimal side effects, using the same dependency injection approach as the main library.\n\n### Register\n\n```csharp\nusing Cake.Bridge.DependencyInjection.Testing;\n...\nserviceCollection\n    .AddCakeCoreFakes();\n```\n\n### Fake Implementations\n\nThe following fake implementations are provided:\n\n| Fake Type          | Original Interface | Description                                  |\n|--------------------|--------------------|----------------------------------------------|\n| FakeConfiguration  | ICakeConfiguration | Mock implementation of configuration         |\n| FakeEnvironment    | ICakeEnvironment   | Mock environment with configurable settings  |\n| FakeFileSystem     | IFileSystem        | In-memory file system                        |\n| FakeLog            | ICakeLog           | Capture and inspect logging output           |\n| FakeConsole        | IConsole           | Mock console for testing console output      |\n| FakeRuntime        | ICakeRuntime       | Mock runtime information                     |\n| FakePlatform       | ICakePlatform      | Configurable platform information            |\n| BridgeArguments    | ICakeArguments     | Test arguments collection                    |\n| FakeProcessRunner  | IProcessRunner     | Mock process execution                       |\n| FakeProcess        | IProcess           | Mock process with configurable exit codes    |\n\nEach fake implementation can be configured during registration:\n\n```csharp\nserviceCollection.AddCakeCoreFakes(\n    configureFileSystem: fileSystem =\u003e {\n        fileSystem.CreateFile(\"/temp/test.txt\", \"test content\");\n    },\n    configureLog: log =\u003e {\n        log.Verbosity = Verbosity.Diagnostic;\n    }\n);\n```\n\n### Example Tests\n\nFor practical examples of testing with these fake implementations, see the test project in this repository at [src/Cake.Bridge.DependencyInjection.Testing.Tests](src/Cake.Bridge.DependencyInjection.Testing.Tests) using [Verify](https://github.com/VerifyTests/Verify) and [xUnit](https://xunit.net/).\n\n\n","funding_links":["https://github.com/sponsors/devlead"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlead%2Fcake.bridge.dependencyinjection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlead%2Fcake.bridge.dependencyinjection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlead%2Fcake.bridge.dependencyinjection/lists"}