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
2 answers
292 views

C# coding style, functional approach

I have thought of this for a while and I want to know what you think about this. This is more of a way to structure the code that might not be 100% object oriented and that is not the purpose. I would ...
Cowborg's user avatar
  • 109
4 votes
3 answers
732 views

Does it make sense to put all related records in one source file

With C# 9 and the introduction of record a lot of boiler plate code was remove from pure data objects. And after watching a dotnet community video on YouTube where then "joked" about it's ...
Qben's user avatar
  • 151
0 votes
3 answers
475 views

Common code at beginning of all implementations of an interface - c#

I have an interface that looks like this: public interface IInterface<T> where T : IParameterType { void InterfaceMethod(T param); } And a lot of implementations of this interface, each ...
RJKVictor's user avatar
1 vote
3 answers
1k views

When Should I Use a Static Class and When Should I Just Use Functions?

I am currently building a C# application that gets JSON data then it calculates something then stores the results in a database, what is the proper way to design the application. This is how it's now ...
BeeFriedman's user avatar
1 vote
1 answer
115 views

Using the decorator pattern to populate entity properties

I have products saved in my database that my system fetches with the following structure: public class OriginalProduct { public string Id { get; set; } public string Name { get;set; } } I need ...
filur's user avatar
  • 127
-1 votes
3 answers
564 views

Refactoring multiple non-nested if statements [C#]

I have a number of non-nested if statements that look like this: if (!bytes[nameof(PropertyVersion.Price)].SequenceEqual(dbBytes[nameof(PropertyVersion.Price)])) changes += $"Price {TextHelper....
Azhari's user avatar
  • 115
0 votes
1 answer
103 views

Distribution of processing across cores between a LINQ and PLINQ query

I am trying to create a simple demonstration of using 'parallel LINQ' (PLINQ). I have two versions of my task, in C#: var result = Enumerable.Range(1,1000000).Where(x => IsPrime(x)).ToList(); ...
Richard Pawson's user avatar
1 vote
1 answer
308 views

Domain Driven design and representing process state

I'm trying to find a good way to implement state transitions for a job posting. This is just an experiment in trying to write better code. You can find the code and a diagram in this repo. The main ...
Rob's user avatar
  • 19
2 votes
1 answer
164 views

Proper orchestration of NServiceBus sagas

I'm seeing two ways of orchestrating NServiceBus sagas. I'm not familiar with it so I'm trying to understand if they are just two alternative ways of doing the same thing or if I should follow one or ...
Scott Hannen's user avatar
0 votes
0 answers
101 views

Best practices when it comes to extending Service collections in .NET for dependency injection

Most of the information that I can find online is about how to do basic dependency injection in the common flows. eg one DI container where services are registered. For a project we are writing a ...
Robin's user avatar
  • 103
28 votes
3 answers
9k views

Is it Good Practice to Only Expose Interfaces

I''m working on a C# library where the API provides several public interfaces and a single concrete factory class (itself an interface implementation). This factory provides implementations of the ...
Bondolin's user avatar
  • 393
2 votes
2 answers
202 views

Abstracting calls to common library methods in C#

I‘m working on making a legacy code base more testable and made good progress with (constructor)-injecting dependencies to classes. I noticed something in all classes that access the file system: they ...
Der_Reparator's user avatar
1 vote
3 answers
422 views

Design pattern for feature toggling

To simplify the domain let's say we have a system that takes in orders from customers. There's an API endpoint that validates the input, and if valid pushes the order onto a messaging queue to be ...
Serberuss's user avatar
  • 139
1 vote
1 answer
1k views

Correct IHttpClientFactory implementation with dependency injection?

In Microsoft's documentation, in the Named Clients example, they retrieve an HttpClient from the IoC container: var httpClient = _httpClientFactory.CreateClient("GitHub"); In the Typed ...
chrisxfire's user avatar
0 votes
3 answers
897 views

Is It Considered Good Practice to Use Dependency Injection with Strategies from a NuGet Package?

I am developing a NuGet package which contains shared code for various ASP.NET Core projects. I am planning to use the strategy pattern to solve the same problem in a few different ways. So there will ...
Treker's user avatar
  • 151
0 votes
1 answer
837 views

Mocking / stubbing C# record types in a unit test

I have a series of record types in my C# project that I use with JSON.Net to deserialize json data. public record RadarrMetadata( IReadOnlyCollection<string> CustomFormats ); public record ...
void.pointer's user avatar
  • 5,003
1 vote
1 answer
474 views

DDD - Modelling a system of groups and users

I'm looking for some advice on a system I'm designing, at its core it will allow users to create/join/manage groups of users. I thought it would be a good idea to try and apply some DDD principles, ...
Astronought's user avatar
0 votes
1 answer
249 views

Best way to name derived classes when extending its functionality [closed]

I have just recently joined a new company and one of the classes used to log information has not been written properly. So I have been asked to add new functionality to the logger. Rather than ...
user16405900's user avatar
1 vote
3 answers
119 views

Multi type HTML dropdown conversion to the corresponding C# object type

Note: This is a contrived example I came up with to illustrate what I'm after as simply as possible. I have an HTML report with a single dropdown box at the top that lets the user select (or filter) ...
Scuzzlebutt's user avatar
1 vote
3 answers
628 views

Domain Driven Design - Aggregate Root and Nested Aggregate Invariants

I've come to a bit of an impasse with the best way to implement a DDD problem, and am hoping for some advice from those with more experience, please. I have a RecipeCollection, which has a collection ...
danwag's user avatar
  • 119
0 votes
1 answer
138 views

Is there a best practice for storing multiple pages of JSON responses from an API?

Scenario: An API that responds to a request with multiple JSON objects contained in an array. The responses are paginated such that each page returns an array of JSON objects. I deserialize the JSON ...
chrisxfire's user avatar
0 votes
1 answer
429 views

MVVM - Wrapping Class For ViewModel

I am using a networking library I created which contains a Client class. I have a GUI which will display all these clients in a ListView with columns, such as one containing their online status. The ...
lol's user avatar
  • 113
2 votes
2 answers
295 views

How to come up with an easy-to-use way of creating quantities with units in C#?

I want to come up with a way to make it easy to write classes that represent quantities with units, such as length, weight, etc. For example, var height = new Length(32.2, LengthUnit.M); var weight = ...
redcurry's user avatar
  • 133
1 vote
2 answers
494 views

C# - Class creating instances of other classes requiring different services

Context I have a service class whose sole purpose is to interact with a specific API, let's say the Automotive API. The API mostly works with generic AutomativeRecord which basically represents a ...
Union3008's user avatar
0 votes
0 answers
616 views

WPF - Custom MenuItem with buttons or new Window? (or other?) - Update : what is your opinion of my solution?

Context I'm currently doing a project with WPF, which I'm fairly new to. What I am trying to do is a custom and configurable taskbar-like application. What I currently have I managed to create a ...
Error 404 Brain not found's user avatar
0 votes
2 answers
202 views

Struggle with catch 22 in initialization code

I have a command line application written in C#. Here's some facts about the program that are relevant to my question: The application has a "data directory" (e.g. ~/.config/myapp) where ...
void.pointer's user avatar
  • 5,003
0 votes
3 answers
216 views

Hardcoding endpoints in library alternative

I'm dealing with creating a few internal libraries for a project that can offload emails and logs to a queue (Service bus, storage queue). The issue I'm having is how to configure the the queueing ...
KryptoBeard's user avatar
0 votes
1 answer
223 views

Best way to accept a lot of user input from command line

I have a program that accepts computer names and then will perform CIM session tasks. The computer names are passed in from the user input and separated by "," (ex: program.exe -computers ...
James's user avatar
  • 11
0 votes
1 answer
70 views

Good approach to design Business interface for versioned API?

I am designing an API using .NET core 6 C# which has 2 versions. For v1 I have something like the following for the business logic interface (fictional names and simple fields just to facilitate ...
the-4th's user avatar
  • 101
-1 votes
1 answer
424 views

How to handle third-party libraries that can potentially throw, without knowing what kind of exceptions they may have?

I'm starting to run into this sort of dilemma while many third-party APIs, but I will use MongoDB for my examples. Consider the following code: var settings = MongoClientSettings....
Saturn's user avatar
  • 3,887
-1 votes
3 answers
496 views

Would Injecting dependencies in C# as default parameters be a bad practice?

Given the (old) debate over whether Singletons are overused/abused/are worth it - would it be a bad idea to inject the dependencies as default parameters? In this way, we could get rid of defining ...
Veverke's user avatar
  • 383
-3 votes
1 answer
117 views

Using two different languages where one would suffice for the task (microservices)

I previously asked this on StackOverflow, but doesn't fit there and I was suggested to move it here. I was thinking about using two seperate backend languages for seperating concerns in a project of ...
HackXIt's user avatar
  • 97
11 votes
4 answers
4k views

Should we abandon the "if not null" pattern?

I've seen that with the Dictionary API now has methods with bool TryGetValue<TKey, TValue>(TKey key, out TValue value) and I like this kind of methods because they're signaling to the other devs ...
MaxouMask's user avatar
  • 350
2 votes
2 answers
106 views

Calculate operation time and setuptime or costprice based on a variable set of parameters - Design Pattern?

I work in a production company where my colleagues calculate costprices based on 3D models and their respective operations. Apart from workactivities where a user has to insert an operation time and ...
Jannick Breunis's user avatar
0 votes
0 answers
175 views

Implementing the Repository/UnitOfWork pattern using Azure.Data.Tables "TableClient"

I currently have a generic Azure repository AzureRepository<TEntity> store internally a list of table transaction actions like so. private readonly IList<TableTransactionAction> ...
Reap's user avatar
  • 183
-1 votes
1 answer
344 views

State machine using SOLID principles. Connecting to real devices

I am trying to implement code for switching states of a couple laboratory devices. My considerations are: how should I link the state objects, state machine object and device manager object to follow ...
Martin's user avatar
  • 1
0 votes
1 answer
251 views

Blazor Application separation of concerns

I am building a cross-platform application and have planned to use Blazor. I have made similar applications in the past but using ASP.Net Core for the back-end and Angular for the front-end. I always ...
J.Paravicini's user avatar
0 votes
1 answer
639 views

How to implement automatic SemVer from code changes [closed]

Goal I'm working on libraries published as nuget packages and I would like the version of those packages to update automatically based on the changes I make. In other words, I would like something ...
Batesias's user avatar
  • 234
0 votes
0 answers
80 views

Doubts designing an old system using DDD

We have the following system: References that identify a product and have a family which identifies a group in which the reference belongs. Families that are a way to group references, for example, if ...
mmas's user avatar
  • 33
-2 votes
1 answer
219 views

How Should I Go About Refactoring My Code With Dependency Injection? [closed]

I work on WPF applications used in testing hardware. I need to make my code base more testable and re-usable. I believe DI would help, but I'm not quite sure where to start. I've done my best with the ...
Dink McDinkleman's user avatar
1 vote
0 answers
1k views

WPF Best way to create viewmodel from another viewmodel

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 ...
user2190492's user avatar
5 votes
6 answers
468 views

Unsupported concurrent calls, throw exception or log a warning?

Context Let's say I have a navigation service that allows me to navigate to a page. The Navigate method is async because an animation (about 250ms) is involved. public interface INavigator { ...
Batesias's user avatar
  • 234
1 vote
1 answer
94 views

Contextual Implementation Overhead vs Redundancy

I have an application that has use cases relative to where it is used. A local client and server, where all the server data is in a single location and the client queries that server knowing it is ...
FinalFortune's user avatar
1 vote
1 answer
2k views

How to handle duplicate validation logic with CQRS pattern

I am implementing a CQRS pattern in ASP.NET Core with MediatR, and I am wondering what the general consensus is for handling duplicate validation logic for queries/commands which operate on the same ...
Mark Lisoway's user avatar
0 votes
2 answers
183 views

How to handle continual method addition to an existing class

I find myself often adding more and more methods to a specific class, is this class heading in an unmaintainable direction? Or is this class fine even if it has 50 or more methods? let's call the ...
Nifim's user avatar
  • 151
0 votes
2 answers
309 views

Which strategy to use to create object instances

I have this use case (I've simplified it): Each student can apply for one or multiple activities. As of now we only have Swimming activity onboarded on the system, but we expect to have more. Base ...
Juanma's user avatar
  • 109
5 votes
4 answers
7k views

How to get an ILogger instance from extension methods?

Let's say I have this service abstraction exposed from a library. public interface INavigator { ImmutableList<IPageViewModel> Entries { get; } void NavigateForward(IPageViewModel page); ...
Batesias's user avatar
  • 234
0 votes
1 answer
225 views

Architecture solution for scalable crawling

I have the following requirements: a list of queries (rather long list ~ 100K - 1M items or even more) that I need to perform in a certain period of time and the execution time must be predictable. ...
Yevgeniy Yemelin's user avatar
1 vote
2 answers
2k views

Where should helper classes/methods for transforming business data for the View be located

I have inherited a badly architected and organised ASP.NET MVC application, which is an online booking system for healthcare providers. It seems to have been designed with very few object oriented ...
Kyohei Kaneko's user avatar
3 votes
3 answers
2k views

Why would you have a different namespace for each folder in a C# project?

I can't see how having a namespace for each folder makes sense. As near as I can tell, the point of having namespaces is to avoid name conflicts. But, Microsoft, in their namespace naming conventions, ...
Josiah_Maddux's user avatar

1 2
3
4 5
98