Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c#]

C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform

1
vote
2answers
55 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
24 views

Developing SDK for a Device? [on hold]

I need to develop a SDK that will run on a device. This SDK should faciliate communication between any device which is using our SDK and our API Service. I specify some methods for a device, these ...
0
votes
0answers
23 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 ...
1
vote
3answers
118 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
5 views

WPF MVVM validate property before setting when user's change value in DataGrid [migrated]

Issue: I have a list of a class that's being displayed in a Datagrid, one of the values needs to ask the user if they really want to change it. This was implemented with a YesNo MessageBox in the ...
0
votes
0answers
124 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
0answers
43 views

Are my UML's understandable and do they follow the UML conventions? [on hold]

I'm new to software modeling and was hoping someone could walk me through mistakes I've made. I'm trying to show how my parser for our game is working. Said in words, the parser is supposed to take ...
3
votes
3answers
134 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
49 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 ...
-2
votes
0answers
25 views

Implementing Microservices Architecture in .NET WEB API [on hold]

Currently we have setup the .NET WEBAPI 2 Projects in our application as backend project. Which consist of Kind of hybrid solution like monolithic and MicroServices. Our Project scope is getting ...
0
votes
2answers
53 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 ...
6
votes
1answer
222 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
125 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
91 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
78 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
1answer
65 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
498 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
26 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
308 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
156 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 ...
0
votes
0answers
8 views

Attempted “__set__” operation on ASN.1 schema object [migrated]

I'm currently using IronPython to execute Python code in my .NET project. The issue, however, is that I am receiving an error: Attempted "__set__" operation on ASN.1 schema object This is the C# ...
3
votes
5answers
288 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
206 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 ...
0
votes
0answers
17 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
377 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
69 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
32 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
31 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 ...
1
vote
2answers
107 views

Refactor API to return additional object

I have a c# library that sends requests to a number of HTTP endpoints and then tries to de-serialize the result into the specified type. An indicative method is defined as: public virtual async Task&...
1
vote
0answers
38 views

Extending IdentityUser with nullable foreign key to another IdentityUser

I'm working on a framework which builds on .net core Identity. Let's say I wanted to extend the IdentityUser<TKey> class with a ParentUserId property while the developer should still be able to ...
2
votes
1answer
278 views

Two-level concepts

I find myself lately implementing the same concept twice, once at a low level and once at a higher level. Let me see if I can explain it... For example, given the notion of a database, I have one ...
4
votes
2answers
265 views

Repository pattern usage

I need some advice regarding repository pattern. Let's assume i have UserBal which stands for business logic which uses UserRepositoryDal where all database logic for that entity stands (queries to ...
0
votes
1answer
139 views

Do I need to unit test a generic method with all accepted types?

For a method whose signature looks like this: public T Add<T>(T first, T second) where T : struct, IEquatable<T>, IComparable<T> which can work with all of the integral types, do I ...
0
votes
2answers
62 views

Passing runtime-read configuration when working with an IoC container

I've recently "discovered" the IoC realm, and decided to refactor a project I'm working on to use such a container. To be specific - I'm using autofac in C#, in a .NET Core console application. The ...
0
votes
2answers
116 views

Building Client Specific Application on Top of Standard Application

I have a standard application and in this case, it is an Accounting ASP Net MVC application. Now, I have a new client that has their own specific requirements like other fields and some custom ...
1
vote
1answer
87 views

Simple Audit Logging Design

I have a C# MVC application. One of the requirements of the application is to maintain an audit log of everything that happens to a particular 'entity' page. To make the example concrete, lets say ...
0
votes
1answer
90 views

Reset state or create new objects

I am developing a desktop application that will be run at each station at a call center. It listens for an incoming call, and whenever a call arrives, there are about 30 different classes that need ...
0
votes
1answer
84 views

Setters in ViewModels

So I have started reading some books and articles on architecture. They all state (put a little simply) that you should never let your view access the model directly, when using a Model-View-ViewModel ...
2
votes
2answers
251 views

Why does C# type pattern matching use a different variable scoping behavior than traditional switch blocks?

Traditional switch blocks have one scope, so the following throws a compiler error "A local variable or function named 'message' is already defined in this scope": switch(value) { case 1: ...
0
votes
1answer
82 views

What's the better way to organize retrieval of difference in props

I have a system, which stores different objects in DB. Each such object has properties. Some of them are relevant for all objects (like Name, Description), but some are specific to each object and ...
3
votes
1answer
136 views

Way to hide logic behind class for better readability of method and refactor class to follow SRP

I have an algorithm to create a version for an entity and then I save that version against below 2 entity: 1) Variant 2) Category interface IEntityVersion { string GetVersion(); } public class ...
1
vote
0answers
65 views

How to make view models more DRY? [closed]

When looking at the WPF view model code samples on the web/books almost all of them show same approach for the bind-able properties that are used for the binding and input in the UI and that often ...
0
votes
1answer
102 views

Network Communication - queue processing thread/task or?

I have an application that is sending messages over a socket from different threads. I create my own wrapper for the socket that enables me to extend functionality. Example - on new ...
-2
votes
4answers
158 views

Handling an exception thrown in a catch block [closed]

If I'm writing a method, in C# for example, I will use a try catch block. Let's say the method adds some numbers but I log exceptions in the catch block. What's the best way to handle an exception ...
0
votes
0answers
63 views

Inherit a class that inherits a generic class to make it easier to read

I'm creating a simple Dependency Injection library for Unity (no constructors available) and I want to use a generic class that implements a generic call for each class that would inherit it allowing ...
1
vote
1answer
61 views

Should all my asp.net MVC controllers use Web APIs?

The thing that I don't understand is the prioritization between MVC Controllers and Web APIs. Consider I want to make a website. I can either program to APIs and for the presentational layer, force ...
0
votes
0answers
56 views

What's the best way to control distribution/usage of proprietary, internal software?

I was tasked with writing software for my company. As I am now writing a third program (with many more coming), what's the best way to control the distribution/usage of our software? The software I'...
2
votes
1answer
168 views

Must we define methods and async when we don't know whether the implementation is synchronous or asynchronous?

I think I know the answer to this, but it's particular enough that I don't want to go telling other people stuff until I'm 100% certain. Suppose I have a class with some dependency: public interface ...
0
votes
2answers
94 views

Would you use the mediator pattern for this scenario?

I'm wondering if you would use the mediator pattern on the following scenario. First of at all, the program must call an API, and persist this response on somewhere (it could be a database, a file, ...
0
votes
3answers
118 views

How to handle views and logic in a Winform C# app? [closed]

I come from a webdev background so I'm used to MVC to handle the separation between the views and the logic (and the data/models). I'm starting to develop using Winforms in C# and I want to know what'...