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
1
vote
1answer
31 views

Are resource files (.resx) secure?

I have a resource file called AppSecrets.resx, and the bit of code below to check the login credentials of the "super duper admin user". This admin user is distinct from normal admin users, as it is ...
-1
votes
1answer
44 views

CQRS and GraphQL

Context Domain I have a CQRS domain with requests, authorizers, handlers, response objects, entities, filters, pagination. It only depends on: external services (email, other APIs, etc...) a ...
0
votes
1answer
97 views

How can I get rid of a dependency in a single branch?

I am working on an API solution, split in three projects: API Domain DataAccessLayer I have created an interface, in the Domain project, ICustomerRepository, with a single method: Domain.Customer ...
1
vote
3answers
156 views

Are Result objects the cleaner way to handle failure, than exceptions? [duplicate]

I was watching the following video by Vladimir Khorikov, which recommends to "Refactoring Away from Exceptions" pluralsight.com - Applying Functional Principles in C# - Refactoring Away from ...
1
vote
4answers
119 views

What if there is specific logic for one particular value of an enumeration class?

Background: I have seem some argument for using enumeration classes instead of enum in C#, in particular, this section from a book available at MSDN. On the references there is this "Enums are Evil" ...
1
vote
0answers
70 views

Is using a non-compile-time-constant value as a default parameter a code smell? [duplicate]

I'm trying to use App.config and Configuration Manager for the first time. I wanted to use some values in App.config as default parameters for some methods, but this results in an error (not a compile ...
2
votes
2answers
175 views

C# extension methods design patterns and usage guidelines?

C# extension methods have seen a rise in usage over recent years. The offical microsoft guidelines on usage state: "In general, we recommend that you implement extension methods sparingly and only ...
0
votes
0answers
59 views

Repeated code in the modular REST API [closed]

I have built the REST API which is divided into several modules. I'm currently working on data validation (I create my own attributes). Attributes can be used in many modules. Since the API is ...
0
votes
0answers
85 views

Code Design: Repeatedly doing the same Boolean check with Stream Writer

I have several areas in a program where I am doing the following check on the same two booleans, but each spot has different text being written to a file via Stream Writer based on the value of the ...
0
votes
0answers
35 views

Logging OpenCV Mats [closed]

We'd like an abstraction for writing images (OpenCV Mats) to disk for diagnostic purposes during image processing. As we currently use the Serilog logging library (through ILogger in Microsoft....
46
votes
7answers
11k views

Managing and organizing the massively increased number of classes after switching to SOLID?

Over the last few years, we have been slowly making the switch over to progressively better written code, a few baby steps at a time. We are finally starting to make the switch over to something that ...
0
votes
0answers
54 views

What is a good design for maintaining consistency in a last write wins database without event sourcing

We have an application which on every resource update(resource update, create, delete)creates a message and puts it on a queue. This message is picked up by a worker process, converted to a format ...
0
votes
1answer
63 views

c# Fluent Builder and invalid object state

I have a question about Fluent Interface Builder. I have a simple object like this: public class Person { public string Name { get; set; } public string Surname { get; set; } public int ...
0
votes
2answers
91 views

How to initialize base class property once instead of passing it from all derived classes?

I have a small library where I am performing 1 long running operation and based on that operation,I am saving some data inside database tables.Now this is small library which does not include alot of ...
0
votes
1answer
20 views

How to handle adding new field / partial data update for a gRPC API?

Assuming we have following message that will be used to update data and it just got updated to version 2. message HelloRequest { string name = 1; // version 1 bool is_valid = 2; // version 2 } ...
0
votes
1answer
51 views

How to populate view models

So let's say I have a view model, representing a student. The view model is corresponding to a student model, from which the data comes. What I am struggling with, is how to populate the fields in the ...
1
vote
2answers
104 views

Refactor namespaces in a library while keeping backwards-compatibility

We developed a generic .NET library for our line-of business applications. This is what our namespace/class structure looked like 5 years ago: ... AcmeCorp.Tools.ExcelWriter AcmeCorp.Tools....
8
votes
5answers
1k views

When should we use dependency injection (C#) [closed]

I would like to be sure I understand the concept of dependency injection (DI). Well, I actually understand the concept, DI is not complicated: you create an interface then you pass the implementation ...
1
vote
4answers
161 views

Dependency injection / testability - would this logic be appropriate?

In a testability perspective, would this logic be appropriate? public class Foo { public List<SomeClass> Elements {get; set;} public Foo(IServiceInterface service) { this....
0
votes
3answers
179 views

Dependecy Injection vs Singleton Pattern

I just read documentation and tutorial about dependency injection (DI) and the singleton pattern (SP). Everybody seems to says DP is bad and DI is the way to do it. Tutorials about dependency ...
0
votes
0answers
37 views

How do you expose the field that caused the error?

Context: field errors Given an input in the form: { "list": [ { "username": null }, { "username": "test" }, { "username": "" } ] } Some APIs expose errors in the ...
0
votes
2answers
117 views

SRP violation confusion based on examples

I am trying to gain better understanding on SRP and when I was checking out a Pluralsight video by Scott Allen, I saw code like this: https://github.com/OdeToCode/cs-fundamentals/blob/master/src/...
-1
votes
0answers
71 views

ASP.NET Web API map a custome exception to a HTTP error code [migrated]

This question is about software development methods and good practices and architecture I'm working on a Web API in C# using Web API MVC. Here is a sample of one of my controller: public class ...
1
vote
0answers
87 views

SOLID Principles and writing clean code. Am I wrong? [duplicate]

I really need some advice as I've recently come into a conflict over a difference of opinion on the SOLID principles and writing clean code. One of our, relatively new developers but senior, does not ...
1
vote
0answers
31 views

Assigning default filtering values for complex API request model before passing it to business domain?

I am writing an API (web-service) for my customers and there is an endpoint which allows to search for the documents in my storage (files, folders) by applyingg complex filters. Initially, client ...
0
votes
1answer
248 views

Refactor multiple “if” in C#

for (int i = lstReportCount - 1; i >= 0; i--){ if ( (input.ServiceTypes == "1" && lstReport[i].A == 0) || (input.ServiceTypes == "2" && lstReport[i].B == 0) || (input....
0
votes
3answers
137 views

Domain Models with complex properties construction

According to this article: Using Ids in Domain Models is not a good practice. We should reference the entire domain model instead. In this case, when we want to provide only Getters for our ...
1
vote
2answers
104 views

Best practice when creating classes that are solely in charge of the creation of other objects i.e. factories?

I often find myself creating classes that I suffix with 'Factory'. These classes tend to be solely in charge of the creation of a specific class or set of related classes. However I've always felt ...
0
votes
0answers
44 views

Synchronization data between API (server) and local database : C#

I hit an API which gives a list of chairs with their location. I save this data in my local database. Whenever I received updated data like add a new chair, update location of the chairs and delete a ...
2
votes
3answers
188 views

Dealing with API errors

I'm building a shop system which works in three parts: a mobile app (Android/iOS) which is used by customers to make orders, view products and so on, a desktop application, used by the managers to ...
0
votes
0answers
137 views

Should I check for nulls, even though I won't get any, as far as I know? [duplicate]

I'm new to software engineering and right now I'm focused on learning the best practices to consistently write robust code. Recently I've been maintaining an application built by other people and/or ...
3
votes
3answers
165 views

Is this a good method of separation?

I am creating a web application that is tiered in the following way: Controller > Service > Repository I have a ProductsController which has the following action: [ValidateModel] [HttpPost] public ...
0
votes
2answers
73 views

Entity unique identifier in domain driven design

I'm just learning DDD and a question raised in my mind about unique identifiers in an entity. Consider this simple method that checks the uniqueness of an entity to prevent duplication: private ...
0
votes
2answers
54 views

When no other class ever needs to touch the (nested) class - should I always make it a (private) nested class?

And what is the recommended file structure? The question is a bit similar to this one, but I'm looking for more explicit recommendations. In theory I think it's a good concept to keep files short ...
7
votes
1answer
276 views

Is the C# async/Task construct equivalent to Java's Executor/Future?

I'm a long time Java developer, but with so little traffic on SE, I don't limit my viewing to any single tags. I've noticed that C# questions with async/await come up a lot, and as far as I've read it'...
4
votes
1answer
135 views

Architecture to lock account to mobile device

I'm currently creating a mobile app and have the following issue. I am required to only allow the user to login from a device that is registered to the users account. A user can have up to X number of ...
0
votes
1answer
103 views

Where to store calculated values of an entity

Trying to figure out the best place to store calculated properties related to a base entity class for use through out the application, namely in view models and DTOs. For example, a base entity class ...
0
votes
1answer
104 views

How can I use disparate concrete classes that share similar functionality to create an interface that abstracts those similarities?

I've run into this issue a few times. I have preexisting framework objects that do not share a common ancestor. An example of this would be a class representing a an environment variable and a class ...
1
vote
2answers
112 views

Would I have one domain model (.NET Project) for all consumers or one domain model (.NET Project) per consumer?

Say I have a bounded context called: 'Loans' and the following APIs: HSBC NatWest TSB The three banks above are consumers and have an API. I am using the scatter gather pattern (https://www....
6
votes
6answers
539 views

I need help solving a common architectural problem with multiple concrete classes implementing an interface

I have a common issue I encounter which I've solved with a Factory class in the past but it always felt a little "off". Let's say I have multiple Exporter classes which implement IExporter, which has ...
0
votes
1answer
31 views

Venue Reservation System Logic Approach/Clarification

I hope this is the right place to ask since this is a programming related question. I’m developing a venue reservation app (similar to booking.com) and am almost done however I have 1 request for ...
3
votes
2answers
337 views

Should one make the database calls in the constructor or method of a class?

Take the following instance for example: CreditCardApplication class public class CreditCardApplication { public int Id { get; set; } public string FirstName { get; set; } ...
0
votes
2answers
184 views

Best way to match timezone with time offset?

I have a c# solution which uses mssql database to store data. In my database there is a big table of entities (e.g. accounts) for each of which the TimezoneId field is defined. This field is filled ...
3
votes
5answers
304 views

Should I add additional unit tests for this helper method that simply aids in refactoring of code?

I have a method: public static void AddPersonToPeopleList(List<PersonModel> people, PersonModel person) { CheckWhiteSpace(person.FirstName, "FirstName"); ...
1
vote
4answers
254 views

C# How to correctly work with ProgressBar? Architecture look

I am wondering about the correct architecture to work with a progress bar in C#. But maybe it applies not only to C#, because I need an architectural look at this. I'll explain my question with an ...
1
vote
0answers
20 views

Event Sourcing & Redis

I'm using StackExchange.Redis library, it seems perfect. Hard-coded events related BankAccount with ID 1: // UNSORTED COLLECTION public static List<Event> DomainEvents = new List<Event>()...
2
votes
4answers
397 views

Why does C# not have automatic dispatchers

Why does C# make you put in a dispatcher for a different thread to update the UI? Example: Dispatcher.Invoke(() = { lblerrorName.Content = ""; }); It always gives the 'running on different ...
0
votes
1answer
73 views

How to manage user serial keys for an application

I have an application in C# where several users access it. Each user will have a serial key associated with his username in a table users in a local MySQL database. Example of the table users: User ...
0
votes
0answers
43 views

MVP pattern in Windows Forms: how to properly open one form from another

I implement MVP pattern in my windows forms application. As you know there is 1:1 means there is one presenter for one view. So basically we can have: public class MainPresenter { IMainView ...
0
votes
0answers
32 views

Is Unity Container Property Injection following Bridge Design?

I have following code written on top of Microsoft Unity. This is the implementation of property injection. I recently gone through a Bridge Design Pattern that separates abstraction from ...