kurumi
kurumi
CC#
Created by Frite on 6/26/2024 in #help
how can I avoid chaos like this ?
at least you can create extension method to avoid this boilerplate code or write custom SG
18 replies
CC#
Created by Frite on 6/26/2024 in #help
how can I avoid chaos like this ?
don't forget other snippets included: multiple functions to change console colors (aka Console.SetRed() / Blue / Green / etc), get all processes in OS (aka Processes.Google / notepad / vscode / etc). it is super useless
18 replies
CC#
Created by DevLop games on 6/24/2024 in #help
✅ Namespace error
$close
63 replies
CC#
Created by DevLop games on 6/24/2024 in #help
✅ Namespace error
no, that's ignore it
63 replies
CC#
Created by DevLop games on 6/24/2024 in #help
✅ Namespace error
sometimes I save my time by doing compilation manually with terminal
63 replies
CC#
Created by DevLop games on 6/24/2024 in #help
✅ Namespace error
intelisence bug
63 replies
CC#
Created by Alizer on 6/20/2024 in #help
mapping a dynamic object to an existing object and only map properties that exist in the source obj
If the purpose is dynamicly changing values, it is better to use JsonPatchDocument<T> here is guideline https://learn.microsoft.com/en-us/aspnet/core/web-api/jsonpatch?view=aspnetcore-8.0
11 replies
CC#
Created by Yonatan on 6/19/2024 in #help
Teaching C# - Basic and Advanced topics (that are must learn)
to be honest, Auth is not beginner friendly udp: even for experienced devs it is pure madness :harold:
13 replies
CC#
Created by Spaxter on 6/18/2024 in #help
Method on DI service doesn't do anything
what's wrong with blazor DI?
20 replies
CC#
Created by Spaxter on 6/18/2024 in #help
Method on DI service doesn't do anything
how you register _db?
20 replies
CC#
Created by Ale on 6/15/2024 in #help
✅ Dependency injection
haha, I wonder if discord team add full colorized MD support, that will make life easier :when:
16 replies
CC#
Created by Ale on 6/15/2024 in #help
✅ Dependency injection
$di
16 replies
CC#
Created by Ale on 6/15/2024 in #help
✅ Dependency injection
AddSingleton, AddScoped and AddTransient injects them, if we are talking specifically about ASP NET
16 replies
CC#
Created by Ale on 6/15/2024 in #help
✅ Dependency injection
they are called dependency containers (or something like this, I don't really remember, XD).
16 replies
CC#
Created by Ale on 6/15/2024 in #help
✅ Dependency injection
so now you invert of control dependencies to somewhere else. In real situations we have some systems to control our dependencies, which injects everything you need.
16 replies
CC#
Created by Ale on 6/15/2024 in #help
✅ Dependency injection
now let's do some DI. Instead of controlling all dependencies inside of your SolarPanelService you tell: "Yeah, I have some things which I depends on (and they are also depends on others)", so you need to get them for your service, and now we call constructor:
public class SolarPanelService : ISolarPanelService
{
+ private readonly IWeatherService _weatherService;

+ public SolarPanelService(IWeatherService weather)
+ {
+ _weatherService = weather;
+ }

public bool CanActivate() => _weatherService.GetCurrentWeather() == Weather.Sunny;
}
public class SolarPanelService : ISolarPanelService
{
+ private readonly IWeatherService _weatherService;

+ public SolarPanelService(IWeatherService weather)
+ {
+ _weatherService = weather;
+ }

public bool CanActivate() => _weatherService.GetCurrentWeather() == Weather.Sunny;
}
16 replies
CC#
Created by Ale on 6/15/2024 in #help
✅ Dependency injection
DI aka dependency injection is all about IoC (inversion of control). Imaginary a situation when you are creating solar panels service. It needs to know what is the current weather. You have your weather service:
public enum Weather
{
Sunny,
Rainy,
};

public class WeatherService : IWeatherService
{
public Weather GetCurrentWeather() => Weather.Sunny;
}
public enum Weather
{
Sunny,
Rainy,
};

public class WeatherService : IWeatherService
{
public Weather GetCurrentWeather() => Weather.Sunny;
}
so you can normally use it for your solar panel service:
public class SolarPanelService : ISolarPanelService
{
- private readonly IWeatherService _weatherService = new WeatherService();

public bool CanActivate() => _weatherService.GetCurrentWeather() == Weather.Sunny;
}
public class SolarPanelService : ISolarPanelService
{
- private readonly IWeatherService _weatherService = new WeatherService();

public bool CanActivate() => _weatherService.GetCurrentWeather() == Weather.Sunny;
}
so, now take a look at this line
- private readonly IWeatherService _weatherService = new WeatherService();
- private readonly IWeatherService _weatherService = new WeatherService();
as you see your are creating your WeatherService inside of another service. And now imagine that your boss told you to add logging into weather, then to add cache system, then to add email for some reason (idk, maybe boss wants to send weather email, XD). So, it becomes more and more complex
- private readonly ILogger _logs = new Logger();
- private readonly ICache _cache = new Cache();
- private readonly IEmail _email = new Email();

- private readonly IWeatherService _weatherService = new WeatherService(_logs, _cache, _email, ...);
- private readonly ILogger _logs = new Logger();
- private readonly ICache _cache = new Cache();
- private readonly IEmail _email = new Email();

- private readonly IWeatherService _weatherService = new WeatherService(_logs, _cache, _email, ...);
so it is super complex now...
16 replies
CC#
Created by pape on 6/5/2024 in #help
Need help with mvc,NullReferenceException: Object reference not set to an instance of an object.
debug controller
79 replies
CC#
Created by ZombieLab#0088 on 6/5/2024 in #help
help with grenade FPS game
I think it is better to ask this question in $unity discord server. This one is more general C#
3 replies
CC#
Created by Gipper on 6/5/2024 in #help
Easiest and simplest way to insert a Microsoft SQL Server DB into an app saving data in csv files?
but it can be done easier without all these host abstractions and technics such as DI, just create instance of DbContext and use it
20 replies