Questions tagged [c#]
C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform
4,894
questions
7
votes
6
answers
3k
views
C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?
In C# and C++, an apparent trend is in place to reduce / avoid inheritance:
C#: "Sealing types can improve performance."
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/...
0
votes
0
answers
16
views
Where to add WebApi in a service repo design pattern project?
I am hoping someone has had to do this before and can help.
I have a multi tier MVC application that I need to add WebApi, in preparation for moving to .Net Core + react and a new set of controls for ...
-3
votes
0
answers
60
views
C# correct design for creating a decoupled methods or services [closed]
We have a requirement in .net microservice architecture, where we need to have two different operations, one is to support old functionality and second is to create a new functionality, so our our ...
0
votes
0
answers
17
views
Designing an Accepted/202 endpoint
I have an end point where a user can start an update operation. I don't want to make the user wait for the result. There are two possible outcomes:
The action is succesful - nothing to do for the ...
-1
votes
0
answers
86
views
Proper abstraction for third-party API?
I'm writing a library in C# that is meant to abstract calls from a third-party API, such that it can accept inputs from multiple potential applications. Currently, I have three broad classes:
Base ...
0
votes
1
answer
73
views
How to organize "master" data VS "working" data in MS SQL
I have this survey software that I'm writing and I'm wondering what would be the best design for my requirement.
I'm going to simplify it as best as I can.
I have these entities:
class Survey {
...
0
votes
1
answer
84
views
What C# Object Composition strategy would you apply for CoreObjects with a governing 'ObjectType' property
In a C# ASP.Net Core Web Application I have a Domain Model CentralDesignObject made up of many component objects & properties, producing a significant amount of derived/calculated values.
This ...
0
votes
2
answers
188
views
Clean Architecture: Loading data for the domain layer
Let's say my domain has a User Entity that has a many to many relationship with itself representing "Friends"
public class User
{
public int Id;
public IEnumerable<User>? ...
0
votes
0
answers
39
views
Correct way to represent acquaintance enforced by interface in UML class diagram
Suppose I have the following client code:
using System;
namespace InterfaceCompositionUml
{
internal class Program
{
static void Main(string[] args)
{
...
0
votes
0
answers
24
views
Update notification through api end point to SignalR hub or directly in SignalR hub
For updates on a dashboard, I need to decide to make an extra api end point which creates a message in SignalR or let some kind of message broker (filewatcher1) do that. What would be good ...
0
votes
3
answers
106
views
How can I keep accurate time in a Windows Forms (WinForms) application?
I am an inexperienced developer fresh out of college. I was handed a Windows Forms Application to work on.
The application previously relied on system time. They wanted me to make it so that we could ...
-1
votes
5
answers
90
views
Poolable classes with default custom properties/logic without affecting OOP hierarchy
I want to make my own pooling library.
By design, I want each poolable class to have a reference of the pool it came from, so ideally whenever the user wants to make a class poolable they'd have to ...
1
vote
2
answers
75
views
MVVM: How and should I expose view models' models to other view models?
Many times while writing MVVM apps in C# I've come across this sort of problem where I need to expose the model in a view model so that I can get it in another view model and do something with it.
...
0
votes
3
answers
128
views
Can the application layer extend the domain models?
I write BFF (Backend For Frontend) and it's domain is to provide user info and microservices integration.
The User domain model looks like below:
public class User
{
public required Guid Id { get; ...
1
vote
2
answers
131
views
Where to put DLL specific settings?
I'm not sure how to manage configuration settings in a C#/.NET environment. For simplicity lets say I have 3 assemblies: My MainApplication is the project being started and containing the business ...
1
vote
4
answers
250
views
Validating data classes with nullable properties that should never be null
When retreiving data with an api and saving it in a DTO, some values are nullable: null on initial class initialization but VS also warns you for this. For example, an employee:
public class ...
0
votes
2
answers
293
views
Deserializing/Serializing a cached domain object breaks DDD principles
My application has to maintain a stateful object and update it periodically based on events received. I get an initial HTTP request to create this stateful object. After that the object has to be ...
0
votes
0
answers
27
views
Per Request Authorization using Facebook Login
Stack: ASP.NET Core + Razor + SQLite
TLDR: How do I rely solely on Facebook Login for authorization?
I am building an app with sole integration to Facebook for my Facebook group. Essentially it is a &...
1
vote
3
answers
161
views
Isolate or Redundant Test?
I have lots of code like the following. An "Entity" type that has some numerical properties. To be able to reuse the arithmetic I write the arithmetic functions against an interface. I use ...
1
vote
2
answers
374
views
WPF MVVM - Pass data from child-view to parent
I'm trying to implement the MVVM-pattern in a new WPF-application.
I'm using the MVVM Community Toolkit to reduce boilerplate code that comes with the pattern.
In my application, I'd like to have a ...
0
votes
2
answers
118
views
Domain Project and Identity Project circular dependency
I am currently working on implementing the Clean Architecture pattern using Entity Framework. However, I've encountered an issue related to the design of my Domain project. In this project, I need to ...
0
votes
3
answers
228
views
Use of Visitor pattern rather than enums
Lets say that a enum exists:
public enum SomeEnum
{
FirstValue,
SecondValue
}
It's use is spread through the code and all sort of wonderful logic hangs off it.
If we now add another entry (...
0
votes
1
answer
71
views
Generic message broker based on WCF
I apologize in advance for a long-read question, but i'm hardly stuck here and don`t how to ask for help using fewer words.
I need to implement a middleware service which should be placed between two ...
1
vote
2
answers
481
views
Why does IDictionary not implement IReadOnlyDictionary
I've recently just noticed that IDictionary does not implement IReadOnlyDictionary. I'm using two third-party libraries, one of which provides a ToDictionary() method which returns an IDictionary ...
5
votes
2
answers
212
views
Is there a way to avoid downcasting or improve design?
I have the following interfaces to allow me to generate "drawing" of some product.
public interface IProductDrawer
{
public string Execute(ProductScope scope, ProductConfig config);
}
...
-1
votes
3
answers
104
views
How to pass simulation information to a simulated device that uses a generic interface?
Currently, I am developing a software in C# (.NET 6) that tests devices after production. Therefore, it runs specific tests, e.g., voltage measurements, using the connected hardware. If the voltages ...
1
vote
2
answers
174
views
Is there a name for this pattern of sealing base classes to a strict set?
In C#, it's possible to create a strictly sealed set of classes that inherit from a base that cannot be further extended like so:
public abstract record MyBase
{
public sealed record A: MyBase;
...
-1
votes
7
answers
569
views
If you use Inversion of Control, what alternatives to obfuscated function calls exist?
Consider a class that follows the obfuscated function call anti-pattern. I've also seen these called "stupid classes". The definition of such a class is that it only has one public method ...
0
votes
0
answers
124
views
Dependency Injection Usage
I'm very new to DI, and must admit, am having a hard time understanding to what extent it should be used in an application.
Even in a basic project, you can have hundreds of classes that have ...
0
votes
2
answers
333
views
Mediator Pattern in c# - using a mediator to trigger policies
I'm wondering how i can implement what Im calling "business policies" in my code? For discussion purposes, let's say I have two separate contexts - synchronizeUsers and Licensing.
The ...
4
votes
2
answers
319
views
Passing data through events to adhere to the Tell-Don't-Ask principle?
In my little WinForm app, intended to practice as a hobbyist, I'm using this code to pass data from the View to its Presenter:
public event Action<object, string, string?>? SearchInAlbums;
...
2
votes
3
answers
329
views
Is having many build-once factories a sign of bad dependency injection design?
I have a form. It contains things like grids. Users do things with these grids and what they do with them is sent to a SQL server. Clearly, the server is a volatile dependency and should be dependency ...
1
vote
0
answers
63
views
Options for C# machine to machine communication [duplicate]
I’m evaluating different options for communication between C# applications. My requirements are:
Central server where clients connect
Persistent connection, server should know when clients connect/...
0
votes
4
answers
212
views
How to safely store application data on shutdown?
I am writing a Windows Service using the Windows Background Worker Service template. Some data that I track needs to persist between application instances (i.e. after shutdown and restart).
Initially, ...
0
votes
1
answer
144
views
Is a message queue the right pattern to use for intra-module communication in a .net core application
Background Information
We have a .Net core application that uses Hangfire (pretty version of cron) jobs to batch process different types of data.
As a bogus example, we have one job that will run ...
0
votes
6
answers
558
views
Is it best practice for each call to a SQL Server to be in its own class, even when using dependency injection?
I often see/write classes that contain every part of the application where the application will talk to a SQL server. For example, you may have a class like this
public class Data
{
private Func&...
-1
votes
2
answers
109
views
Flexible design approach vs maintainabilty/verifiability
Currently, I have to define a general design approach concerning the future extensibility of a software written in C#. The software is built in modular design: A main part doing the general handling, ...
2
votes
4
answers
1k
views
My concrete classes only have a constructor. Everything else comes from an abstract class. Is this bad practice?
I think that I've taken the Open-Closed and Single Responsibility principles too far. Previously, I had one huge static class containing every method that has C# talk to stored procedures on my SQL ...
0
votes
1
answer
63
views
API design with conditional compilation: stubs and exceptions vs public API change?
I am developing a package for the Unity game engine. I want to add additional functionality to my package if another specific package is present. I am faced with a dilemma I am not sure which of these ...
-1
votes
3
answers
621
views
How to properly design database in accordance with DDD
My Domain layer contains below model:
public class ApiResource
{
public bool Enabled { get; set; } = true;
public string Name { get; set; }
public string ClientId { get; set; }
public ...
0
votes
1
answer
102
views
Dependencies traveling through hierarchical viewmodels
Often I want to open a new window from within some view.
I see opening a window as view logic. So I don't want code in my viewmodel that creates/opens/changes Windows or anything else that
interacts ...
0
votes
0
answers
93
views
SQL Database design for reusable components and classes
I am working on a small suite of enterprise applications, and I am trying to determine the best way to make them more consistent and maintainable across the board. The applications are .Net Blazer ...
0
votes
1
answer
212
views
Observer pattern using static events
I'm working on a game prototype: I have a Cell class which, given a mouse click on its collider, can raise an event that should be listened in two different modules: Camera and UI.
The Observer ...
-1
votes
1
answer
71
views
Optimal OOP security for PubSub - Should mutual consent be required?
I am implementing the Publish-Subscribe pattern.
I have class Broker and interfaces IPublisher, ISubscriber.
interface IPublisher {
broker: Broker;
publish(channel: Channel, data: object): ...
0
votes
3
answers
953
views
The best practice of storing different types of variables in an array in C#
I ran into a modelling problem while solving an assignment of mine. Say I have json string that I need to parse, process it in some way and serialize it back to json. The problem is this json contains ...
0
votes
2
answers
114
views
Designing inter class tasking in C#
I'm looking for some advice/recomendations on structuring an application which involved multiple classes that need access to each other for the sole purpose of tasking (i.e. class A needs to pass ...
0
votes
0
answers
175
views
C# Azure Function Durable Function Vs Batch Timer Trigger Function
I have a question related to the best approach when resources are limited, such as on the Azure Function consumption plan.
I have an IoT device, and the number of IoT devices is likely to increase to ...
-1
votes
1
answer
182
views
Avoid use of the visitor pattern in this very common scenario
Let's assume we need to send a message, and to do so we would like our client to be concerned only with constructing the message (DTO) and using a facade service to send it.
We already know that we ...
1
vote
2
answers
149
views
Wrapping Business Logic In Extension Methods For POCOs
I have recently stumbled upon a use case of extension methods and wanted to gather some design thoughts.
The problem:
A IEnumerable of a POCO and within that list there should exist a POCO that ...
1
vote
3
answers
225
views
Improving performance of C# Azure function
I am currently working on a C# Azure Function that is triggered by an HTTP request. The function's purpose is to extract raw data from Azure Table Storage and output it to the user in the form of a ...