public enum ProductEnum{ INSTANCE}public static class ProductEnumExtensions{ private static int state = 0; public static void DoSomething(this ProductEnum it) { System.Console.WriteLine("I did something for the {0} time", ++state); }}
public enum SingletonEnum { INSTANCE; int value; public int getValue() { return value; } public void setValue(int value) { this.value = value; }}
public class NoDI{ private readonly IServiceOne _serviceOne; private readonly IServiceTwo _serviceTwo; public NoDI() { _serviceOne = new ServiceOne(); // ServiceOne that I need to re-use _serviceTwo = new ServiceTwo(); _serviceTwo2 = new ServiceTwo(); // want ServiceTwo to be new every time }}
C#<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup></Project>