Questions tagged [c#]

C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform

Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

Replacement for WCF ServiceBus Relay in .Net 7

We've leveraged WCF Azure Service Bus Relay fairly heavily in the past and have a number of C# services that rely on it. All of these services relay REST requests to small on-site servers that sit ...
Molloch's user avatar
  • 101
1 vote
2 answers
189 views

Should my methods return concrete classes or interfaces?

I'm building a ASP.NET Core Web API and the application consists of 3 main modules. Data module: Contains the entities and DbContext Web API: Contains the controllers Service module: Contains all the ...
Yashoja Lakmith's user avatar
-2 votes
0 answers
26 views

What is the way of creating custom Reactive attribute? [closed]

I work with Reactive UI library for my WPF applications and was curious about how does the [Reactive] attribute work. I found out that there is nothing there in the attribute itself so there was a lot ...
crackanddie's user avatar
0 votes
2 answers
119 views

Repository concerns

We have a layered application with (basically): WebAPI, App Services, Domain and Repository layers. This fits for most situations, but now we face a slightly different challenge on where we need to ...
zameb's user avatar
  • 109
0 votes
1 answer
215 views

Why are sealed classes not allowed to be mocked?

Using Moq framework, it is not allowed to mock a class in C# which is sealed. Same goes for many other frameworks as well. But why is it not allowed?
Akshunya's user avatar
  • 111
1 vote
3 answers
64 views

Refactoring Controllers publishing different events with MediatR library

I have Controller that basically publishes different Event based on some input criteria, simplified version of the logic is here: [HttpPost] public async Task<ActionResult> Create(...
Velocoder's user avatar
  • 129
0 votes
0 answers
80 views

Designing message handler

I am writing an application that receives different kinds of messages from an external device. The messages are of different types and they are received from the device in the form of a string. For ...
Codisattva's user avatar
0 votes
1 answer
120 views

How best to share common steps between services while allowing them to provide their own behaviour

I've started working on a C# codebase. There are three services which run the same set of steps of three kinds of objects, each returning IResult: public IResult FooService(Foo foo) { ... } public ...
hyperfiction's user avatar
0 votes
2 answers
132 views

What is considered best practice for managing dependency injection for multiple libraries with ASP.NET Core Web API?

Suppose we are building a REST API with ASP.NET Core. Suppose there are 3 projects in our solution: The ASP.NET Core Web API project. A class library project for the businnes layer. A class library ...
user1969903's user avatar
5 votes
2 answers
2k views

C#: Refactoring an oversized try/catch/finally

Recently I've come to discover that I've inherited one of the internal auxilliary programs used. I've made a few minor fixes and features to improve it in the past, but now I've been given a major ...
rdi_pck's user avatar
  • 61
0 votes
0 answers
27 views

parent correlation id in message with rabbit queue and open telemetry

I have a rabbit queue that I use to communicate between applications. I have a chain of three message. App 1 generate and push a message in rabbit(message 1) App 2 catch the message and generate ...
user3401335's user avatar
2 votes
1 answer
198 views

Best practices for team development with NuGet projects in .Net

TL;DR I want to change the way our current enterprise code base is constructed to utilize NuGet packages for the inter-project references, but that seems to present some challenges when considering ...
James Feazell's user avatar
0 votes
1 answer
137 views

Class Hierarchy for Generic Parameter Optimization Problems

I am working on a code library containing data structures and algorithms for solving parameter optimization problems. A parameter optimization problem is a problem of the form: given a vector of ...
Treker's user avatar
  • 179
1 vote
2 answers
217 views

DDD Logic implementation

Ive been tossing this around in my head for awhile. But I'm working on a project that consists of an Order, that has a OrderStatus. There is quite a bit of logic that revolves around the status and ...
KryptoBeard's user avatar
0 votes
2 answers
116 views

Implementing reusable pipeline-style pattern involving different types

I've been struggling with refactoring my code to use a generalized design pattern for a theme I see being repeated. The biggest struggle is that each instance of this repeated code uses different ...
void.pointer's user avatar
  • 5,003
12 votes
6 answers
5k 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/...
user avatar
0 votes
0 answers
23 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 ...
QubeSimon's user avatar
0 votes
0 answers
20 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 ...
Jannick Breunis's user avatar
0 votes
1 answer
101 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 { ...
Francis Ducharme's user avatar
0 votes
1 answer
96 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 ...
freedomdev's user avatar
1 vote
2 answers
264 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>? ...
MyUsername112358's user avatar
1 vote
1 answer
78 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) { ...
user32882's user avatar
  • 267
0 votes
0 answers
40 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 ...
Jannick Breunis's user avatar
1 vote
4 answers
206 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 ...
mpAppProg's user avatar
-1 votes
5 answers
102 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 ...
Saturn's user avatar
  • 3,897
1 vote
2 answers
235 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. ...
aelsi2's user avatar
  • 21
0 votes
3 answers
156 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; ...
Szyszka947's user avatar
1 vote
2 answers
162 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 ...
NoConnection's user avatar
1 vote
4 answers
600 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 ...
Jannick Breunis's user avatar
0 votes
2 answers
645 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 ...
user1890098's user avatar
0 votes
0 answers
30 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 &...
Zathura's user avatar
1 vote
3 answers
167 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 ...
Dave Cousineau's user avatar
2 votes
2 answers
810 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 ...
Sam's user avatar
  • 65
0 votes
2 answers
138 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 ...
pakerinjo's user avatar
0 votes
3 answers
324 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 (...
Postie's user avatar
  • 11
0 votes
1 answer
84 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 ...
Алексей К.'s user avatar
1 vote
2 answers
671 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 ...
Andrew Williamson's user avatar
5 votes
2 answers
219 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); } ...
Dusan's user avatar
  • 585
-1 votes
3 answers
107 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 ...
Thern's user avatar
  • 105
1 vote
2 answers
179 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; ...
ScottishTapWater's user avatar
-1 votes
7 answers
587 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 ...
J. Mini's user avatar
  • 1,007
0 votes
0 answers
127 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 ...
wforl's user avatar
  • 19
0 votes
2 answers
518 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 ...
dot's user avatar
  • 541
4 votes
2 answers
450 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; ...
Valmont's user avatar
  • 173
2 votes
3 answers
344 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 ...
J. Mini's user avatar
  • 1,007
1 vote
0 answers
64 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/...
Markus Knappen Johansson's user avatar
0 votes
4 answers
271 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, ...
PatJon6's user avatar
0 votes
1 answer
184 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 ...
dot's user avatar
  • 541
0 votes
6 answers
765 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&...
J. Mini's user avatar
  • 1,007
-1 votes
2 answers
111 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, ...
Thern's user avatar
  • 105

1
2 3 4 5
99