Skip to content

Files

Latest commit

7ed45bb · Feb 9, 2025

History

History
54 lines (41 loc) · 1.3 KB

global-compositions.md

File metadata and controls

54 lines (41 loc) · 1.3 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 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 net9.0 (or later) console application
dotnet new console -n Sample
  • Add reference to NuGet package
dotnet add package Pure.DI
  • Copy the example code into the Program.cs file

You are ready to run the example 🚀

dotnet run