Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.42 KB

global-compositions.md

File metadata and controls

56 lines (42 loc) · 1.42 KB

Global compositions

CSharp

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, "Off");
}

class MyGlobalComposition2
{
    static void Setup() =>
        DI.Setup(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