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
2
votes
1answer
121 views

When to publish domain events when handling transactions in the application service

This is something that has been bothering me for quite some time, I tried different approaches over the past year but I always come back to reflect on this, so I'll throw myself out here ! So, first ...
-4
votes
2answers
95 views

What is the benefit of Java collection streams over C# or Scala collections?

Java collection streams were introduced in Java 8, which came out in March of 2014. By that time, we already had well-established mechanisms for manipulating collections in several other languages, ...
4
votes
2answers
234 views

Incorporating immutable signatures in C#?

I realize this is a subjective question, but after studying F# and functional programming I've seen the benefits of immutability. Now, I'm thinking of getting rid of mutability entirely in C# unless ...
-2
votes
1answer
44 views

How to organize my controllers in projects in .Net API?

I'm working on a project that is a API with many controllers and modules. Which of the following is the best architectural practice to organizing my API controllers by dll (.NET 4.7 WebAPI)? Why? ...
-2
votes
6answers
193 views

Should a helper function that remove duplicate spaces also trim the string?

In my opinion it should not since it violates single responsibility principle, but I am finding myself often calling both. Edit: here are the 'boring' details: As you all know, we cannot escape the ...
-3
votes
1answer
65 views

Best Way to Extract Different Types of Data from Text File

I am working on a problem where I need to extract data from text. I first considered using regular expressions, but some of the data is not in a format I am sure how to handle or even if regex is the ...
0
votes
1answer
105 views

Email via a Microservice

We currently have a monolithic code base which we are in the process of extracting some micro-services where it's obvious to do so. One thing that stands out is our email delivery. We have numerous ...
3
votes
1answer
256 views

How to handle failed API calls in C#

I built my API service and now I want to consume the information from a WPF application. So far I created the class ApiHelper which initializes and provides the HttpClient used to call the API ...
0
votes
1answer
81 views

Avoiding duplicate code between the player and npc classes deriving from Unity's MonoBehaviour

These would be the base classes like Npc and NpcTask. public abstract class NpcTask { public Npc Npc { get; private set; } public NpcTask(Npc npc) { Npc = npc; } public ...
2
votes
1answer
75 views

Inject Decorators

I recently learned about the decorator-pattern to dynamically extend existing behaviour. So I have this code: IMyInterface b = new A(); if(someCondition) b = new B(b); if(secondCondition) b = ...
1
vote
1answer
82 views

DDD referencing child of aggregate root?

I am trying to learn DDD. I am modeling a property management domain and I think I have two contexts (subdomains?): a property management context and a resident context. Let's say I have an aggregate ...
1
vote
1answer
94 views

SDK design: Should I parse enum as string or as enum?

I am building a SDK that will simplify the use of my API. The problem is if when I have to return property of type enum. For example, I use strings instead of int for displaying enum such as { "...
-2
votes
2answers
126 views

Dependency of program code on specific database values

I have two approaches to solving a problem but I don't know which one is better. I will give a simplified example. First approach The database will look like this: color | -------- FFFFFF | 0000FF ...
1
vote
1answer
205 views

Why no async functions for Utf8JsonReader and ReadOnlySequence

I have used Utf8Json a lot (it is very good) but have since adapted some lower level code and started using Utf8JsonReader directly. Looking into the code of the Utf8Json library, I see ...
0
votes
3answers
360 views

How to design a statically typed REST API client?

Last time I used I created a REST API client in .NET I used exceptions to represent status codes which don't indicate success. (404 was returning null). It's been quite some time since then and my ...
-1
votes
1answer
87 views

Should file download preference be decided in front-end or back-end?

In the project I am working on we are building a feature where you have a file with 2 buttons. Button 1 opens the file in your browser, button 2 starts downloading the file. I see these as 2 distinct ...
0
votes
0answers
19 views

Can a common ActiveMQ service be shared in a dev environment without messages being consumed between developers?

Our dev environment is currently sharing an ActiveMQ service hosted on AWS. This however resulted in problems where dev A's service produce a message that will trigger dev B's localhost consumer. Is ...
0
votes
3answers
130 views

Is it good practice to create a facade only to be able to mock the wrapped implementation?

I'm currently writing unit tests for ASP.NET Core Controllers. Some controllers inject UserManager<T> which seems to be a really hard type to mock. After some attempts to mock or even fake it, I ...
4
votes
4answers
1k views

Is this WHERE clause builder an over-engineered design?

I've got to build some somewhat complicated WHERE clauses in SQL for a project I'm working on, and the clauses feel very hierarchical with their combination of ANDs and ORs. Instead of: WHERE ([...
-1
votes
1answer
37 views

pub/sub events to/from microservices in different languages

I'm starting a brand new project implementing microservices with domain driven design. We will have microservices written in different languages like C#, Python, and Node. I'm thinking about hosting ...
0
votes
1answer
170 views

How do I stop a repeated action?

This is for C#. Ok so I'm coding a very basic money-managing program. You have an account with money in it and you deposit funds into it or you withdraw funds from it. Obviously you don't want to ...
-3
votes
1answer
44 views

Do you recommend having a template scripts?

I am pretty much new to programming, but recently I began to learn C# intensively for Visual C# and for Unity. I have noticed that I use many scripts that have absolutely the same content in different ...
3
votes
4answers
160 views

Extension points via inheritance vs via delegate fields

In C#/.NET, I have a class that I want to provide extension points for. I can do this either using inheritance: public class Animal { public virtual void Speak() { } } public class Dog : Animal { ...
3
votes
3answers
289 views

Coworker wants to use POST to pass ID's in API routes

We've recently started working on an API, and I'm running into a philosophy issue. This is only my second API I've worked on, but the standard I've seen for retrieving a single model is always a GET, ...
3
votes
3answers
214 views

Multiple classes depend on one object reference

I have several classes like Button, Textbox and so on but at instantiation of those object they all need one object reference. The button represents a physical button on the screen but it is not an UI ...
0
votes
1answer
57 views

Process AMPQ messages both reliably and fast

I am new to RabbitMQ and herewith I want to make sure that I am not missing out on some advanced RabbitMQ feature or pattern I am not aware of. I need to develop a reliable system that processes a ...
2
votes
3answers
150 views

Are methods a bad practice on .NET Core EF entity classes?

Say you have the following entity that represent an exact resource from a table, we're talking .NET Core with Entity Framework Core, code-first approach. public class Person { [Key] public ...
1
vote
3answers
80 views

Design Pattern when base class supports new method overload

The base class (in the base lib, not owned by me), has upgraded its code and add a new method to support additional use cases. This is the existing method signature in the base class: public void ...
0
votes
1answer
59 views

How to handle a situation when I have references to an object that should be removed

I have a situation like this: in my online game, players are represented by class Player, which is instantiated and assigned their socket upon their connection to the server. When simplified, some of ...
0
votes
2answers
81 views

How to implement a chain of events on a tree's CRUD operations?

I am working on a project in which I have a tree with 4 layers and the hierarchy is like this. Customer -> Site -> Location -> Guardroom In DB each entity has its own table and the child knows its ...
3
votes
3answers
140 views

Issues with an interface treating a synchronous action as async

Let's say I'm trying to write a library that abstracts certain actions. In this example I want to turn a light on or off. There could be hundreds of different kinds of lights that are controlled in ...
3
votes
3answers
644 views

Design pattern: How to inject dependencies into a Command pattern

I am pretty new to programming languages and only have limited knowledge about design patterns, so I hope you can help me with the following problem: I have an application that operates on a group of ...
0
votes
2answers
99 views

Should I refactor this class to use a Factory?

Given the following class in a Legacy code base without any UT's. So any refactoring done should be done on the smallest possible scale, just in order to be able to write UT's. public class Person { ...
1
vote
1answer
74 views

Encryption using a nonstandard-IV

So i got a few xml files that need to be encrypted and it works, no problems here. Now since the latest update of the CodeAnalyzers i got a new warning ( CA5401 ) that tells me, that it is a bad idea ...
-2
votes
2answers
163 views

Using const values in factory class to choose implementation

I am creating a small program to parse the contents of Excel files. There are two types of Excel files, containing the same data, but with different templates. It is possible to tell them apart with ...
5
votes
2answers
163 views

DDD Domain Modeling of Transportation Module

I am in the process of trying to model a transportation module for an ERP type system using C# and EF Core. This service is responsible for managing customer pickups and company-owned truck ...
2
votes
1answer
899 views

Implementing clean architecture

I just read the book 'clean architecture' by Uncle Bob and really like the approach. But the big disappointment came when I tried to implement it in C#. I really hope you can help me with some ...
1
vote
5answers
78 views

DDD does this (database)logic belong in the model

I'm trying to figure out where to put business logic and why and where performance fits in. Im trying to get away from the fat logic-filled repositories that we produce a lot in my company. So i'm ...
2
votes
1answer
99 views

Wrapping a legacy project in a test framework

I am working on wrapping an old project written in C# in a test framework. The largest problem I have is that I have a bunch of classes that are all VERY tightly coupled with other classes. All of ...
-1
votes
1answer
50 views

Configuring Controllers and Endpoints in a HTTP API

Let's say you need to create an API around machines, and you want to be able to query machines many different ways: Get List of all Machines Get Machine By ID Get Machines By Client Get Machines By ...
2
votes
2answers
971 views

Is unit of work pattern really needed with repository pattern

I am trying to use EF6 with my project. I just watched Repository Pattern with C# and Entity Framework, Done Right | Mosh video. I understand the necessity of Repositories but I still don't understand ...
0
votes
3answers
216 views

How to avoid global variables for state that is the result of one-time, heavy operations?

There's a scenario I have where, in the main entry point of my C# program, I iterate a directory of managed DLLs, load each of them, and pass a factory object to each of them to get a mapping of ...
1
vote
1answer
96 views

How should I construct a complex object having many dependencies?

Consider the construction of the FixAcceptor type below. The code snippet is part of a unit test. var logSource = LogSource.OnMessage | LogSource.Event; var stateStore = new StateStore(); var ...
-4
votes
1answer
163 views

Is using yoda conditions with c# justified?

It's mind bending experiencing reading code like : "Aggregation".Equals(evt.Id)) I was unsuccessful in trying to talk the person out of this style, maybe I'm wrong? Or maybe I wasn't articulate ...
1
vote
1answer
155 views

Unit testing an existing project by creating interfaces for all public classes (including GUI forms)

This is an existing C# .NET WinForms project. I assume it was not developed with unit tests in mind from the very beginning. It uses a Model-View-Controller architecture, and the backend is a content ...
0
votes
2answers
93 views

How to divide responsibility between poco, writer and converter

I have several POCO´s (simple classes holding data) that I have need to flush from memory from time to time whenever a collection grows too large. Most often I want to upload the data to a REST ...
0
votes
1answer
230 views

Is it good practice to save an entire ViewModel in Session (C# ASP.NET MVC)

I have an C# MVC Application which is basically a large application form. We are using a large ViewModel to store all the information the user enters as they pass through multiple steps in the ...
0
votes
2answers
69 views

Pros and cons of different implementations wrt encapsulation

I have an application. It needs to send emails. We've all been there, done that, got the t-shirt. I've got an IEmailMessage interface: public interface IEmailMessage { string From { get; } ...
-2
votes
2answers
131 views

What is the best way to handle classes descended from the same base class in a collection?

My language is C#. I have a set of seven classes that all ultimately derive from a single class. The image of the class diagram is posted below. I will frequently need to iterate through collections ...
0
votes
0answers
24 views

How to design data persistence in an application which stores data-streams from multiple clients

I'm developing a data consumer application in C# which connects to multiple remote clients over TCP. Since it's C# application, each client is monitored by a Task whose purpose is basically to run a ...

1 2
3
4 5
90