Skip to main content

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
3 votes
3 answers
200 views

Handle hierarchical relationships between large number of enums

I am working on a C# project and I have a somewhat large number of labels (~100) that have some sort of relationships between one another. Here is a minimal dummy example that illustrates this: ...
evolved_antenna's user avatar
0 votes
2 answers
98 views

Resolving dependencies independently of the IoC container

I'm working on a component, let's call it MyComponent, which is intended to be used by various applications. These applications will get MyComponent as a NuGet package for instance. Assume that ...
Akira's user avatar
  • 247
0 votes
1 answer
63 views

.NET - Communication between services and Power BI

I have the following problem which I don't know much about. I have a ServiceA that returns customer data on transactions and a ServiceB that has reports, also my environment uses Power BI from ...
Katarina's user avatar
0 votes
2 answers
87 views

Setting up private properties for unit testing

I'm doing some TDD practice for my own learning. I'm trying to figure out how to transparently set up private properties of an object to support testing. I have a binary tree node: internal class Node ...
mike1952's user avatar
  • 109
0 votes
0 answers
38 views

Multi-tenant (realm based) REST Web API authentication

We're building a multi-tenant setup with a C# Web API and KeyCloak for auth and APISIX as application gateway. APISIX handles the authentication and passes an X-Access-Token to our API when ...
RobIII's user avatar
  • 341
0 votes
3 answers
93 views

Use of environment variable or appsettings as a counter, good or bad practice [closed]

I'm wondering if it's bad practice to have a variable in a webserver which counts the amount of incoming requests and put it in an environment variable. In C# for example you have System.Configuration....
Vincent's user avatar
  • 383
1 vote
2 answers
199 views

OneOf with multiple steps and early returns

Looking for the best way to use OneOf multiple times, returning early depending on the result, specifically if you can get an Error along the way. For example, consider a builder where you need to ...
Joe Enos's user avatar
  • 340
3 votes
2 answers
285 views

Invariant rule in Liskov Substitution Principle

From Liskov Substitution Principle, I am still not very clear about the invariant rule. I read through many posts but I still have doubts. My example is picked from this blog, the example is slightly ...
Rahul Chakrabarty's user avatar
4 votes
1 answer
381 views

Does C# 8 reference type nullability make Option/Result monad obsolete?

As the most common exceptions in my project are NullReferenceExceptions I'm trying to find a way to limit the occurrence of problems with unexpected or unhandled nulls to the minimum. One of the ...
Piotrek's user avatar
  • 151
-2 votes
1 answer
73 views

Pros/Cons of the following code with Autofac DI

I had a discussion with my boss on DI pattern in C# and I would like to get some reviews and discussion on the following code snippets. Key points to look into is that the instantiation of the ...
TPBKK's user avatar
  • 1
0 votes
0 answers
47 views

Azure Service Bus: consume messages from multiple subscriptions vs forwarding messages to a single input queue

I'm designing an Azure Service Bus topology with multiple topics. Each topic is associated with a single message type: this is possible since we have a limited number of message types, each one with a ...
Enrico Massone's user avatar
1 vote
2 answers
145 views

Ensuring partial order of concurrent operations

I have the following operations: User submits event We store event in a queue Wait for events and store them in db for redundancy Wait for events and process them Remove events from queue and db For ...
Cristi's user avatar
  • 187
0 votes
3 answers
329 views

Would you test this piece of configuration code? How do I determine which code is worth testing?

We have a piece of code that decorates an interface to transparently add retry logic. Inversion of Control configuration service.AddOurRestApiClient() .AddResilienceHandler("Retry", ...
LostInComputer's user avatar
0 votes
1 answer
99 views

Where to put the reference to Application Insights in an application designed with the Clean Architecture template?

We are implementing an application by trying to follow the Clean Architecture template for C#. Our application is an ASP.NET core web api and we want to implement the observability for that ...
Enrico Massone's user avatar
0 votes
2 answers
72 views

EFCore In Memory repository Unit Test of Encrypted data

I have in project linq repository unit tests. [Fact] public async Task Get_FromTreeEntitiesUnsorted_RetunsOrderByDescending() { //Arrange _contextReadonly.Entity.Add(new ...
cargt4's user avatar
  • 19
0 votes
0 answers
56 views

Avoiding conflicts with Microsoft Two-factor authentication across multiple web applications help

I'm designing a web application and using Microsoft's out of the box Identity and its default Two-Factor Authentication (with Asp.net core MVC and .NET 8). While setting up and testing the 2FA ...
eaglei22's user avatar
  • 147
1 vote
5 answers
572 views

How are strings simultaneously objects and primitive data types in C#?

In C#, strings can be used like objects with methods, properties, and other features of objects. At the same time, strings are treated the same as primitive data types like int or float in numerous ...
AcinonX's user avatar
  • 613
-2 votes
1 answer
145 views

Resorted to Unconventional( i.e., hacky) "circuitous" programming code techniques when using populating a list of C# Action Delegates via a for loop [closed]

AWS Amazon.S3.Model.PutObjectRequest is merely a 3rd-party AWS Data Transfer Object (DTO) / Plain Old C# Object (POCO) type that can be used to build a request that can be used to send requests to an ...
user1338998's user avatar
1 vote
1 answer
103 views

Storing uploaded images in Azure

I am building a web application with the React + ASP.NET Core template. The application will have a form for uploading recipes, including an image. I am hosting the application as an Azure Web App (...
Jakob Busk Sørensen's user avatar
1 vote
1 answer
304 views

When shall one ignore the absurdity of some code diagrams?

I wrote a relatively small user interface for Unity, whose job is to ease working with parts in a scene, i.e. show/hide/toggle objects to reduce clutter. Long story short, I refactored it to use their ...
aybe's user avatar
  • 765
-2 votes
3 answers
175 views

Class inheritance design with protected methods and run time base handlers

Using C#, I got a class called BaseConfigurations which handles CRUD operations. This class also contains a protected method which is used inside the CRUD handling methods: public class ...
CodeMonkey's user avatar
-2 votes
1 answer
214 views

How to go about version numbers in a C# solution

My current situation: I would like to apply this to a solution containing multiple projects (one executable and different libraries) in C#. Additionally, I have a project that packs the executable, ...
jav's user avatar
  • 113
2 votes
1 answer
151 views

Algorithm for finding all combinations with constraints

I'm looking for a way in C# that finds all the possible combinations with constraints. I've got a list of machines. The machines have capabilities and limitations. I also have a document that defines ...
xtreampb's user avatar
  • 166
0 votes
1 answer
78 views

How to create QueryBuilder to work with concurrent requests

I need assistance with the QueryBuilder that generates OData query. Following is my implementation and it approach has couple of issues If user forgets to SetRootTable then it will cause serious ...
Sunny's user avatar
  • 937
0 votes
2 answers
249 views

Should entities always be simple and mapped?

I am told everywhere that entities are only to represent the data structure, then entities should be mapped to a model and then the model possibly to a DTO. The other way is similar, DTO -> model -&...
Gersalom's user avatar
3 votes
4 answers
351 views

Sorting a sequence according to a hierarchical set of rules

We are producing configuration files for a production system. The configuration files have a dynamic set of variables. Optional values and other values that only need to exist based on other values. ...
Tormod's user avatar
  • 359
2 votes
3 answers
235 views

How to retain the concrete type when writing base-class-oriented code?

A scenario often arises when attempting to make some existing code reusable. I introduce an interface to represent the commonality between some new feature I'm implementing and some existing ...
amarsha4's user avatar
  • 176
2 votes
3 answers
211 views

Displaying a list of similar but different objects without resorting to type checking

I'm creating the UI for a "Point of Sale" type page. You can add orders, grouped orders, and custom items to your transaction, and it should display these in a list so you can see what you ...
Conman_123's user avatar
1 vote
4 answers
428 views

What's the alternative to trying to inherit static methods?

I know you can't inherit static methods, and it seems the consensus is that if you feel like you need to, you're doing something wrong. However, I don't know what the alternative is in my case. Please ...
Andrew Dean's user avatar
4 votes
3 answers
921 views

Does it make sense to to abstract serialization/deserialization?

Serialization and deserialization in .NET applications can be achieved using several libraries, e.g. Newtonsoft.Json System.Text.Json Assuming I'm developing a new application where I want to use ...
Dario's user avatar
  • 1,065
1 vote
1 answer
120 views

Reserving Unique, Sequential Group Numbers in ASP.NET Core with EF Core and GraphQL

I am developing an API backend using ASP.NET Core Minimal API (.NET 7) with Entity Framework Core, HotChocolate (for GraphQL), and a Microsoft SQL Server database. I've encountered a specific ...
bealtis's user avatar
  • 19
1 vote
1 answer
106 views

Persisting data in a mobile app backed by a rest API back-end, advices [closed]

So I am working on this mobile application using MAUI, which is backed by a Rest API in ASP.NET Core. I want to be able to use the app offline, and the user can create/edit some data. This data is ...
Toto's user avatar
  • 155
-3 votes
1 answer
138 views

Screen share with Windows Remote Desktop Services

I need to create a WPF application that gives me the possibility to connect to other computers in the same network. I'm looking into Windows Remote Desktop Services, but it seems like it doesn't have ...
Agostino's user avatar
0 votes
1 answer
473 views

Asynchronous execution queue in C#

I'm trying to a create a "Task Queue" that has the following behaviour. Work is added via a Func such that the task is only started when the item is popped off the queue (no when it is ...
wforl's user avatar
  • 159
6 votes
2 answers
778 views

How to get out of a memory usage problem of a .NET application?

As mentioned in some StackOverflow posts (like this one), I'm dealing with a difficult situation: My company is developing some C# applications (being a client-server application). We have migrated ...
Dominique's user avatar
  • 1,786
0 votes
0 answers
69 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
2 votes
3 answers
605 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
0 votes
2 answers
137 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
  • 121
0 votes
1 answer
805 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
84 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
95 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
139 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
508 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
1 vote
0 answers
72 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
801 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
141 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
  • 199
1 vote
2 answers
233 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
2 votes
2 answers
178 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,073
15 votes
6 answers
6k views

Why is it necessary to mark classes as not inherited from? Can't an optimizer automatically detect that virtual calls are unnecessary?

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

1
2 3 4 5
99