textYash
textYash
Explore posts from servers
CC#
Created by textYash on 7/27/2024 in #help
Enum based Singleton
I found this C# based on on a website:
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 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);
}
}
but I don't think the enum plays any role here
15 replies
CC#
Created by textYash on 7/27/2024 in #help
Enum based Singleton
im unable to find any ACTUAL implementation
15 replies
CC#
Created by textYash on 7/27/2024 in #help
Enum based Singleton
yea exactly
15 replies
CC#
Created by textYash on 7/27/2024 in #help
Enum based Singleton
oh okay its actually a thing. I found java implementations online:
public enum SingletonEnum {
INSTANCE;

int value;

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}
}
public enum SingletonEnum {
INSTANCE;

int value;

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}
}
15 replies
CC#
Created by textYash on 7/27/2024 in #help
Enum based Singleton
That's what I don't understand... I kinda have no one to ask what's to be done
15 replies
CC#
Created by textYash on 7/26/2024 in #help
Purpose of Dependency Injection
Thanks a lot again!
24 replies
CC#
Created by textYash on 7/26/2024 in #help
Purpose of Dependency Injection
Cool
24 replies
CC#
Created by textYash on 7/26/2024 in #help
Purpose of Dependency Injection
yea new new new new extravagant lol
24 replies
CC#
Created by textYash on 7/26/2024 in #help
Purpose of Dependency Injection
right?
24 replies
CC#
Created by textYash on 7/26/2024 in #help
Purpose of Dependency Injection
oh okay wait now I get it... that service one inside NoDI can't be reused to be passed to other methods
24 replies
CC#
Created by textYash on 7/26/2024 in #help
Purpose of Dependency Injection
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
}
}
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
}
}
like this
24 replies
CC#
Created by textYash on 7/26/2024 in #help
Purpose of Dependency Injection
@Pobiega & @SleepWellPupper thanks! That helps. What real-world problem would make me feel the need for DI? (because I still feel a lack of clarity in my knowledge which I believe would be met once I solve a real problem with DI)
24 replies
CC#
Created by textYash on 5/23/2024 in #help
Unable to add a new Controller in Visual Studio
I opened .csproj in notepad and it has
C#
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
C#
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
26 replies
CC#
Created by textYash on 5/23/2024 in #help
Unable to add a new Controller in Visual Studio
what's web worload?
26 replies
CC#
Created by textYash on 5/23/2024 in #help
Unable to add a new Controller in Visual Studio
No description
26 replies
CC#
Created by textYash on 5/23/2024 in #help
Unable to add a new Controller in Visual Studio
but still no controller option
26 replies
CC#
Created by textYash on 5/23/2024 in #help
Unable to add a new Controller in Visual Studio
Where should I be looking here?
26 replies
CC#
Created by textYash on 5/23/2024 in #help
Unable to add a new Controller in Visual Studio
No description
26 replies
CC#
Created by textYash on 5/23/2024 in #help
Unable to add a new Controller in Visual Studio
I tried that but I can't find controller on there
26 replies