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
4 votes
1 answer
104 views

I'm working on a WPF application which has many user interactions which start with opening a non model window, allowing some interaction with the window and the rest of the application (think ...
LOul's user avatar
  • 41
2 votes
2 answers
302 views

I’m working on a WPF MVVM application that has grown beyond just one or two User Controls. I now have multiple ViewModels that need to react to each other’s actions (e.g., selecting a customer in one ...
Sam's user avatar
  • 29
8 votes
4 answers
2k views

When using Entity Framework and running the Update-Database command, non-updated applications that rely on the database crash due to database context changes. Usually teams have a production database ...
EMN's user avatar
  • 795
4 votes
1 answer
1k views

My job uses SonarQube as part of the CI/CD quality gate. One of the "Maintainability" issues (severity: medium) raised is the CA-1822: Mark members as static. The link explains the added ...
Veverke's user avatar
  • 541
1 vote
3 answers
244 views

I have a C# library that contains all the logic to send requests to a remote endpoint, including marshalling/unmarshalling and encrypting/decrypting requests and responses. It contains an HttpClient ...
hyt's user avatar
  • 121
0 votes
2 answers
149 views

When using recursion in an extension method, there are two different ways to invoke the method from within itself. Option 1: As an extension method internal static class MyExtension { public ...
Josh Brunton's user avatar
16 votes
10 answers
5k views

I have noticed in documentation, looking at open-source code bases, and just a general sense in the industry that C# developers largely prefer to use List<> or IEnumerable<> over simple ...
K0D4's user avatar
  • 423
2 votes
3 answers
170 views

My team does predominantly back-end work in C#, with a smattering of front-end web development using Angular. We're starting a new website project, based on the Admin LTE framework / template. This is ...
mmathis's user avatar
  • 5,586
0 votes
2 answers
338 views

I have a question about setting up my service. My main concern is if the design is clean and in order. Whether it meets the SOLID principles and does not spill out on me. I have entities like order ...
Petr Klekner's user avatar
3 votes
1 answer
162 views

The move to MVC and MVVM has not been easy for me. Combining multiple languages in single pages with inline code is something I find disorienting. I'd like to remedy this by attempting to use Razor ...
Northern Scrub's user avatar
2 votes
1 answer
179 views

Preface: This will not be available publicly or to third parties, so I am not concerned about users having the background knowledge to properly form GET requests. These are also not only analytical ...
user avatar
1 vote
1 answer
320 views

public void ReassignLineItems(InvoiceUpdateDto invoiceUpdate) { Invoice invoiceInRepository = _unitOfWork.InvoiceRepository .FirstOrDefault(invoice => invoice.Id == invoiceUpdate.Id); ...
EMN's user avatar
  • 795
2 votes
1 answer
144 views

My main focus is having as little duplicate code/files as possible. Most of the HTML I write is almost identical. There is already a form template which holds the form and several necessities. That ...
Roe's user avatar
  • 131
1 vote
1 answer
175 views

In an ASP.NET MVC application with views that make AJAX calls for widgets like dropdowns and data grids, is it better to use Web API controllers or regular MVC action methods that return JSON? The ...
EMN's user avatar
  • 795
0 votes
2 answers
237 views

I am new to C#, and Windows (coming from Python, Linux background). I need to add tests to an existing C# codebase, which relies on a MSSQL database and Entity Framework. In my old days when testing ...
mguijarr's user avatar
  • 226
1 vote
3 answers
516 views

As we know, there are (at least) four ways to instantiate a class object in C#. But I've never quite understood why some ways are better than others. First of all, you can explicitly declare the ...
Cade Bryant's user avatar
1 vote
3 answers
190 views

I am developing some modular libraries that contain common APIs, data, and functionality. One of the core assumptions to these libraries is you would use which you want to compose your project, but ...
SventoryMang's user avatar
4 votes
4 answers
473 views

Microsoft identifies dependency injection as one of the uses for primary constructors. public class ExampleController(IService service) : ControllerBase { [HttpGet] public ActionResult<...
Jannick Breunis's user avatar
0 votes
4 answers
282 views

So I just learned about Expression<TDelegate>. As a library author this really intrigued me; my libraries make extensive use of source generators to generate both high-performance code and code ...
Applekini's user avatar
  • 117
1 vote
1 answer
179 views

What are the use cases of TestOf? I'm new to NUnit testing and from what I have seen, most people don't use this attribute that much. From my experience, TestOf helped me to quickly identify what ...
LNTR's user avatar
  • 43
17 votes
5 answers
3k views

I'm unsure whether parameter names should describe their object types or if shorter, more concise names are preferable. Consider the following two method signatures: public void PrintPoint(...
Abcd's user avatar
  • 297
3 votes
3 answers
979 views

I am designing a fluent builder pattern API that branches and allows different options based on what has already been called. For example: Build().Foo().Bar() is valid code, but Build().Baz().Bar() ...
starikcetin's user avatar
5 votes
5 answers
2k views

In one of the flows we have too many returns that look like this: PaymentResponse<ProviderReservedAccountsResponse>.Failed( new Error( ErrorCode.ReservedAccountsCreationInProgress....
Ah C's user avatar
  • 67
3 votes
1 answer
440 views

I'm starting a new project and I want to follow a Clean Architecture(ish) approach. I've modeled my projects in that manner (attached diagram). For the API I'm using FastEndpoint since I like it, it'...
developer82's user avatar
2 votes
2 answers
528 views

We have a very complex and mature ASP.NET web application that is about 20 years old and has 5 million lines of code spread across roughly 30 project in a single monolithic solution. It's running on ....
Pavel's user avatar
  • 123
-2 votes
1 answer
216 views

I'm working on an ASP.NET Core application that requires handling multiple types of a single entity. Each type has its own properties and validation rules, which has led to confusion and complexity in ...
Marko Sami's user avatar
0 votes
1 answer
260 views

I'm working on an ASP.NET Core application that uses Identity for user management. I have an AccountService with a Register function, where I accept a RegisterBaseDto that contains the role ...
Marko Sami's user avatar
3 votes
5 answers
2k views

I am designing a program and I am looking to decide over a Dictionary vs a List. Since I know I have unique values per item I imagined a Dictionary/List that looks like: Dictionary<(int k1, string ...
Ranald Fong's user avatar
0 votes
3 answers
309 views

To learn about things like microservices, messaging brokers and all other new and fancy things, I decided to create microservices that will let me monitor my base within Minecraft (done via ...
user2463506's user avatar
1 vote
3 answers
620 views

Yesterday I screwed up: One of the classes of my C# contained a property, called "DeliverdQuantity" (yep, there's a spelling mistake indeed). When I saw that, I decided to correct that, ...
Dominique's user avatar
  • 1,844
0 votes
2 answers
128 views

I am practicing tactical DDD and having trouble as exemplified below. Fundamentally, whether some fields of the value object should be nullable depends on another field of the same value object. ...
STHA's user avatar
  • 71
4 votes
3 answers
2k views

I inherited a piece of software. This program is connected to an external hardware, which is a measurement device. Every 100 milliseconds, a value is read from this device and displayed to the user. ...
SomeBody's user avatar
  • 151
0 votes
2 answers
1k views

Say I have an asynchronous method: public async Task DoThing(int x) { // ... } Now, I want to wrap this method with a new method. Each of these two options are functionally equivalent: public ...
AAM111's user avatar
  • 161
1 vote
2 answers
875 views

I'm working on an MVC application using C#/asp. The project is following an n-tier architecture style with a separate data layer, domain layer and presentation layer. My question is related to the use ...
AnabolicMike's user avatar
-2 votes
1 answer
330 views

Introduction Components are an important building block of software. In terms of software architecture, there are a lot of principles regarding components that should be adhered to (high cohesion, low ...
dn1h's user avatar
  • 19
5 votes
7 answers
586 views

Consider the following scenario. I have an interface IService: public interface IService { void DoSomething(); } with an implementation: public class Implementation : IService { // This might ...
Codisattva's user avatar
13 votes
4 answers
3k views

I am writing a C# class and one of the fields is an API endpoint. Being that API is an acronym and is written in all uppercase letters, what is the correct way to name the field _APIEndpoint, ...
BeeFriedman's user avatar
0 votes
3 answers
447 views

I have a Windows service that I would like to extend and add a CLI to it similar to docker or Elastic Agent, so I have a question about what kind of approach I should use for the *.exe to communicate ...
t3chb0t's user avatar
  • 2,601
3 votes
1 answer
455 views

I'm seeking advice on the best approach to upgrade a legacy .NET Framework project to a newer version. The project currently consists of over 80 projects, and a complete rewrite would be a time-...
Asdrubal Hernandez's user avatar
1 vote
0 answers
87 views

When spinning off sections of a (C#) codebase to create libraries/package for use by other users within a team/organization, what are important considerations in terms of code & package ...
freedomdev's user avatar
0 votes
1 answer
317 views

I am trying to apply Robert Martin's Clean Architecture on my .NET project. In one of chapters about boundary, it talks about that database interface should reside in business logic component rather ...
Afshar's user avatar
  • 223
3 votes
3 answers
317 views

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
152 views

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
  • 257
0 votes
1 answer
100 views

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
2k views

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
135 views

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
325 views

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
2 votes
4 answers
920 views

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
  • 350
3 votes
2 answers
418 views

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 ...
riki's user avatar
  • 149
5 votes
1 answer
876 views

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
  • 161

1
2 3 4 5
100