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
1 answer
55 views

What is the best approach when working in a communication between Microservices using Azure Functions?

I'm working in a situation where I have 2 different projects (kind of microservices, but they are still messed up in terms of the tables that each project can access - same domain). But so far, they ...
user avatar
  • 3
2 votes
5 answers
544 views

Class method Vs. Interface?

I am relatively new to C# and OOP concepts in general, but am building a standalone application and have run into a question and want to make sure I'm doing it the "right way". I have a few ...
user avatar
  • 39
1 vote
4 answers
2k views

Is it a bad practice to use Singleton for DI in Asp.net rather than Scoped, Transient whenever possible?

We had a conversation (with coworkers) about why we needed to use Singleton for Controller, Business Services, and Repositories. The reason for this, they claim, is because singleton ensures that code ...
user avatar
0 votes
0 answers
85 views

C# Web API Requests and multipart forms with json and files and not buffering the filestream in memory

I'm looking for some C# web API architecture advise on how best to minimize my memory when doing a "multipart/form-data" request which consists of a json payload with a single file upload. ...
user avatar
  • 1
1 vote
1 answer
109 views

Prevent users with multiple sessions using a single use voucher

I'm working on a .Net eCommerce site that allows users to use vouchers to get free products, discounts etc. The problem I have is that there have been instances of users, who have been issued single ...
user avatar
1 vote
2 answers
225 views

CQRS MediatR Create many items commad - is it a good practise?

I am here to ask question about: is it good practice to insert many records using CQRS and MediatR? how to structure that in terms of names and folders? A have to insert into database over 500 ...
user avatar
2 votes
4 answers
626 views

Is it a bad practice to use transformation functions within DTO objects

I'm looking for some guidance. Is it a bad practice to use transformation functions within DTO objects? I have this example public partial class AgEmpDto { private DateTimeOffset ...
user avatar
0 votes
1 answer
99 views

Which one is good practice to do something like 'out' from C# in JavaScript? [closed]

Since I met the out keyword in C#, I'm trying to find an equivalent approach in JS. So, please take a look at the code and leave your opinions of existing cases or suggestions of new ways to implement ...
user avatar
0 votes
3 answers
118 views

What should be the optimal management of end user messages in N-tier architecture?

I'm curious about your thoughts on this subject that we have discussed with the people around me. Especially at the architectural stage, in which layer is the most optimal and efficient way to use the ...
user avatar
  • 13
0 votes
0 answers
119 views

Blazor server side or client side, towards backend DB

I'm wondering, although as I think both options are possible. Currently, there are two versions for Blazor projects in visual studio 2019. If you want to connect to a backend DB then there are two ...
user avatar
  • 137
3 votes
5 answers
1k views

Am I understanding the new C# naming conventions right?

A couple months ago, Microsoft updated their C# Naming Conventions (https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions). As the developers of C#, I consider ...
user avatar
  • 1,406
0 votes
0 answers
63 views

Can/Should Refit (API) Contracts be the same of MediatR (CQRS) Commands?

I'm creating a microservice using Clean Architecture principles. The following picture shows the project structure: On the Application layer, I am using MediatR (using CQRS), where I have the ...
user avatar
0 votes
0 answers
82 views

INotifyDataErrorInfo error propagation from child to parent objects

tl;dr I was wondering what is the best practice when having complex objects and using INotifyDataErrorInfo and every property can potentially have some validation implemented and a property can be a ...
user avatar
1 vote
4 answers
390 views

How to convince colleagues to stop writing static classes [closed]

I recently joined a new company. After working on some projects I noticed a pattern. Every project contains a lot of static classes. A lot of static Helper classes. ApiHelper JsonHelper UmbracoHelper ...
user avatar
2 votes
3 answers
856 views

Business logic error handling. Should exceptions really be avoided?

C#'s primary error handling mechanism are exceptions and try pattern. We don't have access to discriminated unions yet like in case of F# and Rust Option<T> and Result<T, E> types. The ...
user avatar
  • 1,431
27 votes
14 answers
8k views

What's the logic behind the design of exceptions?

I'm writing an application in C#. I'm facing an InvalidConstraintException, but from that Exception, I seem not to be able to access the Constraint, causing the Exception. That specific question is ...
user avatar
  • 1,643
-1 votes
1 answer
37 views

Looking for way to store, get, partially update few relatively small JSON documents which has different unique types

I have an app with many individualistic features which behavior is controlled by settings. Let's say these are a few utility services with the following settings that are historically stored in ...
user avatar
-1 votes
2 answers
57 views

Applications interested to the same event and concurrency

I have an event pubblished in a bus(rabbit) and two application that are subscribed to this Event. public class CreationEvent { public int CreationEventID {get; set; } ... other properties } ...
user avatar
1 vote
1 answer
506 views

How to unit test public method which internally calls many internal or private methods which are already individually unit tested [duplicate]

In our ASP.NET Core application, we have many APIs which are calling public method from the service class. Service class is implementing an Interface. Each service method (depending upon complexity ...
user avatar
  • 113
0 votes
1 answer
142 views

DDD+CQRS - Should I always check if the Databases are online?

I'm developing an intranet application and I'm trying to use some concepts from Domain Driven Design (DDD) and Command and Query Responsibility Segregation (CQRS) in .NET Core, with EFCore. But, to ...
user avatar
0 votes
1 answer
56 views

Finding/determining future data for pricing

I'm honestly not even sure how to go about how to ask what I'm looking for/need. lol. I'm currently using Sql Server for my database and the 'new' .net 5. There are multiple pricing tables that each ...
user avatar
  • 19
1 vote
3 answers
231 views

Refactoring a class to an abstract base class - keep default implementation in place or move it to an an other class?

I have a class which aggregates some temporal data from a database and provides a bunch of methods to query said data. It looks like this: public class InfoProvider { public IEnumerable<...
user avatar
-1 votes
3 answers
184 views

Running series of steps depending on implementation

What is the "best way" to implement something like this: I have a list of steps that will be iterated and ran for an IContext instance. But, some steps will only apply to a specific instance ...
user avatar
  • 117
-1 votes
2 answers
474 views

Determining the object that caused a null reference exception?

Frequently in applications we encounter situations that could throw a NullReferenceException; for example, assuming the following method's argument is a user defined reference type, accessing the ...
user avatar
2 votes
4 answers
377 views

Best way to return multiple results from a function in C# [closed]

We have function DoStuff. It can return Stuff or Error. What is the cleanest way to do this in C#? I know that it's best to throw in error case, but it has its own downsides. Also consider case where ...
user avatar
  • 363
0 votes
2 answers
155 views

Is it better to pass parameters incapsulated in an object or that those parameters be properties in C#?

I need to create some commands that share the method Execute() and a property that gets the result of such execution: List<IResponse>. I have the following interface: public interface Command { ...
user avatar
0 votes
2 answers
258 views

Finding similar objects in a large data set

I have a large collection of (C#) objects and these objects have a large number of properties, mostly strings and numbers. This collection is stored in a database. When a new object is about to be ...
user avatar
  • 137
1 vote
2 answers
136 views

How to declare a Id value object?

For some more type safety I wanted to introduce a PageId type in my application. However, I am not totally sure what the best option to do so is. I want the IDs to be GUIDs, so I thought I just create ...
user avatar
0 votes
1 answer
86 views

Creating a contract for a UDP connection

I'm developing a system in C# who consists in a desktop application running a UDP server and a android app and this app sends data (byte array) to be read by the desktop application with commands and ...
user avatar
4 votes
1 answer
423 views

Text adventure game: is there a more elegant way to store data & control logic?

so for the past several months, I've been working on a personal project. It's a comically large, highly open, handcrafted text adventure game packed with inside jokes and fun little surprises for my ...
user avatar
1 vote
3 answers
126 views

Logical evaluation with pattern matching in C#?

I'm working with another developer and we're trying to clean up and modernize some legacy code; all the while, trying to keep things readable and remain somewhat surgical with changes [1]. There's a ...
user avatar
1 vote
1 answer
77 views

Behavior Driven Development - How to test "notification" step

I'm implementing the steps of a feature with Specflow and I have a problem with one of the steps. Here is the Scenario : Scenario: Cancel a yearly running subscription after legal retractation ...
user avatar
  • 129
1 vote
1 answer
153 views

C# how to implement a factory class which doesn't require an argument passed to indicate objects type?

I currently working on a parser project in C# and have run into problem. I have an entity folder within my project and within it I have: Entity IEntity.cs (defines a contract for entity classes) ...
user avatar
2 votes
2 answers
188 views

What are some alternatives to translate data models in C#?

I have a need to translate data from provider A to provider B. The data is typically pretty consistent, but, often has minor differences; for example: public sealed class ProviderOneFoo { public ...
user avatar
-1 votes
1 answer
182 views

Hardware test GUI with multiple event sources (4 serial ports and user interaction) - best architecture?

I have the following requirements: Write a GUI app for automated testing of some custom PCB hardware. The system must be usable for a technician with little to no advanced PC skills. The test setup ...
user avatar
1 vote
2 answers
475 views

One API or Two APIs one for internal use and the other for external use

I follow the Layered architecture Like this: But with two differences: I use Blazor Assembly for UI Layer. I have API layer(REST) In between the presentation layer and the service layer. My ...
user avatar
1 vote
1 answer
115 views

How do I ensure that only service models are used as properties?

I work on a system that utilizes a form of n-tier architecture in that we have data and service models. The service models derive from the data models: public class FooDataModel { public int ...
user avatar
6 votes
3 answers
378 views

How to simplify exception handling for library users?

Suppose of having a library exposing the following piece of functionality: public static class AwesomeHelpers { public static async Task<int> ComputeSomethingImportAsync(CalculationInputs ...
user avatar
2 votes
3 answers
371 views

I need help naming a possible movement in a chess game

I'm working on a chess game and have created a base class for game entities and chess pieces, along with an enum for the state of a square, when returned in a collection of possible movements: public ...
user avatar
2 votes
4 answers
198 views

How to make components communicate with each other

I have a simple setup where I've decided to reduce my overall OOP design and opt for lots of small individual components that I can add and remove from a particular object. The whole point of this was ...
user avatar
  • 2,000
0 votes
0 answers
94 views

Multi-threading optimization in-depth

A time ago I participated in an interview process where I was tasked with a simple requirement. I created the best solution I could, using some lock-free implementation. I didn't pass the code ...
user avatar
1 vote
2 answers
540 views

What's the better way to do MVVM with a number of very similar view models?

An important view in our application is a big table of entities. For the purposes of this question I'll use an analogy for our entities - so let's say it's vehicles. There's half a dozen different ...
user avatar
1 vote
1 answer
157 views

SRP, command pattern and design problem

I'm refactoring a code base to have something more easier to read and follow SRP. However I'm at the point I'm unsure what the best design is. Currently it looks like this: A thread receives a "...
user avatar
  • 119
0 votes
1 answer
78 views

Does default deleting behavior of Datagrid violate mvvm pattern and separation of concerns

In WPF when Datagrid's CanUserDeleteRows property is set to true, then conveniently I don't need to implement deletion of elements from an underlying data structure. But it does mean that deletion ...
user avatar
2 votes
1 answer
136 views

Best practice for designing a WebAPI for exposing data in a SQL database interacting with C++ and C# applications

I am looking for general guidance or any relevant links for a complex project. We are a small business that sells a construction materials testing software. The client is a Windows application with ...
user avatar
3 votes
2 answers
253 views

Does creating one thread per event subscriber scale well?

I'm working on an application implemented in different microservices, which uses a message broker (event bus) to consume events (simple pub/sub). As for now, in a given microservice, we are spawning 1 ...
user avatar
1 vote
2 answers
370 views

Are experienced developers and software architects able to describe an entire software application in terms of design patterns?

Do experienced developers and software architects see entire application in terms of design patterns? In other words experienced developers and software architects able to describe an entire software ...
user avatar
2 votes
3 answers
212 views

What is a manageable way to handle physics collisions for many types in C#?

I have a function that takes two objects and uses a switch on the enum types of the objects. The problem I have is this is getting painful to manage as I add more and more primitive types and i need ...
user avatar
  • 2,000
1 vote
2 answers
298 views

How to implement a rule-based decision maker for an agent-based model?

I have a hard time understanding how to combine a rule-based decision making approach for an agent in an agent-based model I try to develop. The interface of the agent is a very simple one. public ...
user avatar
  • 2,242
0 votes
0 answers
293 views

and web api endpoint, which return html from view

I have ASP.NET 5 Web Api and need to do the following task: Add endpoint, which get cshtml page and return generated html, so it should do the same what is does razor view engine. What is better way ...
user avatar
  • 249

1 2
3
4 5
96