Skip to content

Latest commit

 

History

History
60 lines (46 loc) · 1.56 KB

File metadata and controls

60 lines (46 loc) · 1.56 KB

Global compositions

When the Setup(name, kind) method is called, the second optional parameter specifies the composition kind. If you set it as CompositionKind.Global, no composition class will be created, but this setup will be the base setup for all others in the current project, and DependsOn(...) is not required. The setups will be applied in the sort order of their names.

using Shouldly;
using Pure.DI;
using static Pure.DI.CompositionKind;

return;

class MyGlobalComposition
{
    static void Setup() =>
        DI.Setup(kind: Global)
            .Hint(Hint.ToString, "Off")
            .Hint(Hint.FormatCode, "On");
}

class MyGlobalComposition2
{
    static void Setup() =>
        DI.Setup("Some name", kind: Global)
            .Hint(Hint.ToString, "On");
}
Running this code sample locally
dotnet --list-sdk
  • Create a net10.0 (or later) console application
dotnet new console -n Sample
dotnet add package Pure.DI
dotnet add package Shouldly
  • Copy the example code into the Program.cs file

You are ready to run the example 🚀

dotnet run

Important

Global compositions apply to all other compositions in the project automatically, so use them carefully to avoid unintended side effects.