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

How to design a repository when datasource differs based on DML/READ operations?

We are starting our new application in which we using MS SQL DB for all our insert/update/delete/select ie. both SELECT and DML operations. But, soon we will have two different sources. SQL Server ...
2
votes
3answers
92 views

Choosing between derived classes and adding an additional property in entity framework

I have the following StudentGroup class: public class StudentGroup { [Key] public int Id { get; set; } //the set of peers who will review the work of the StudentGroup [ForeignKey("...
1
vote
4answers
355 views

Is creating ViewModels in Web API a bad practice?

So, somebody at work who is twice as experienced than I am, told us that we must not create ViewModel classes within Web API. (We are using Angular for UI) In his opinion ViewModel is ASP.NET MVC ...
2
votes
1answer
92 views

Does it make sense to qualify an error as an HTTP error without an HTTP client-server communication

I am writing a C# client SDK to a REST Api. This SDK sends JSON-serialized models to the API, and implements a first level of verification of the parameters. If the verification fails, it throws an ...
0
votes
0answers
40 views

Where to put property change callback code so I can handle the previous value of the property without using something different than BindableBase?

I have this uncompilable code below, it uses the code in this answer. In it gv means "the old value of a group's name", where a group is a group of clocks, and a clock is a timer or alarm. It ...
1
vote
1answer
108 views

What is the Difference between Reactive Extensions and Message Queue?

I am trying to understand the difference between Reactive Extensions and Message Queue? Are they competing frameworks? Can they be used in conjuction? Started programming, and trying to understand ...
2
votes
1answer
122 views

What is the correct way to get differences for Event Sourcing (C#)

I am looking into Event Sourcing. One of the key points is about saving the differences to the event store rather than objects themselves. This is fine in simple examples. However, I am struggling ...
30
votes
7answers
7k views

How to treat unhandled exceptions? (Terminate the application vs. Keep it alive)

What is best practice when a unhandled exceptions occurs in a desktop application? I was thinking about to show a message to the user, so that he can contact support. I would recommend to the user to ...
2
votes
2answers
210 views

Throw Custom Exception

First, I know - there are a lot of online resources that talk about the topic Exception handling - but yet there is still something that's unclear to me. Consider having this code in an external ...
0
votes
1answer
62 views

Throttling notifications from child ViewModel to parent ViewModel

I have a child view-model which notifies on a property change: public class ChildViewModel : INotifyPropertyChanged { private bool isSelected; public bool IsSelected { get => ...
1
vote
2answers
75 views

Class property re-use vs redundancy

TL;DR - When designing classes for MVC use, is there "best practice" for how classes should be structured to eliminate property duplication and/or redundancy? I'm trying to avoid large (one-size-fits-...
1
vote
0answers
28 views

Using TPL to manage hundreds of contexts

Overview of application: A chat bot that connects via IRC, using TPL. As messages come from the socket (from .ReadAsync()), they are ultimately parsed and passed to a handler within the bot itself (...
2
votes
2answers
267 views

Why doesn't C++ support covariance in STL containers like C# or Java?

The Covariance and Contravariance feature is well supported in C# and Java collections. However C++ doesn't support them in their STL containers. Why is it so? For example the below code will ...
3
votes
0answers
107 views

Daylight savings time for real time application

I am building an application on windows forms C# that will run in real time 24 hours a day 365 days a year. This application tracks the time that components are out of storage. I am running into a ...
1
vote
3answers
199 views

Downcasting in order to call method of subtype

Is it a good practice to have a list containing objects of derived types and then filtering it by type checking when need to call methods specific for one of the types? From what I read typechecking ...
1
vote
0answers
41 views

Grant type/flow to use for multitenant application

Let's image we have a multitenant(organization) application having a separate database per tenant(organization). The core of the application is a REST api service protected by an authorization ...
-1
votes
1answer
226 views

Do C# compilers optimize away the facade pattern?

In C#, if I hide away implementation behind a facade, or the "pimpl" pattern, does the compiler optimize away the intermediate function call if all it's doing is calling an equivalent method from ...
40
votes
3answers
14k views

Why is the logical NOT operator in C-style languages “!” and not “~~”?

For binary operators we have both bitwise and logical operators: & bitwise AND | bitwise OR && logical AND || logical OR NOT (a unary operator) behaves differently though. There is ~ ...
0
votes
0answers
32 views

Registering dependency implemented in separate assembly with shared interfaces

Situation: I have a project with a Business Layer (WizBang.BL) that contains nearly all of my application logic. It communicates with a Data Layer (WizBang.Data) that contains by entity classes and ...
3
votes
3answers
462 views

How to justify using await instead of .Result() or .Wait() in .NET Core?

Since the inception of .NET Core, console apps, function apps, ASP.NET etc. are not using synchronization context in async methods (so they're synchronizing straight to Thread Pool). This means that ...
1
vote
2answers
140 views

Is it better to encapsulate dictionaries in library code?

I work on (big) codebase that consists out of multiple modules that are all built on top of shared library. In this shared library, is it better to encapsulate dictionaries as return values, instead ...
2
votes
3answers
163 views

REST API: what should PUT do with complex objects?

Let's suppose I have the following objects in my domain: class Warehouse { int Id; string Address; Item[] Inventory; } class Item { int Id; string Name; int Price; int ...
3
votes
5answers
276 views

Naming classes representing multiple values - Singular or Plural?

So we've got the following class: public class BudgetAmounts { public readonly int BudgetFk;//Foreign key to Budget public readonly int ItemSalesGroupFk;//Foreign key to the type of product ...
0
votes
4answers
294 views

OO-question re: interfaces and is-a vs. has-a

Disclaimer: the following is written without further distinction in the object oriented terminology as C# is implementing it: classes, interfaces and instances, etc. Let's assume the following ...
1
vote
1answer
230 views

Isn't asynchronicity an implementation detail?

Consider a simple — and fake — interface: interface ISuperGetter { Super Get(); } An implementation would get some Super from RAM. On would store what it needs on disk. Yet another could fetch the ...
0
votes
2answers
158 views

Is there a better way to use Lazy<T> than what I'm doing?

I recently started trying to use the Lazy class to implement lazy loading. However, I'm finding that doing so does not seem to have any advantages over simply implementing it myself via a null-...
0
votes
1answer
118 views

Why is it bad to map between a Model and a ViewModel in an extension method

In a recent Pull Request (PR) of mine, a colleague suggested that it was a bad idea to map between a model and its view model via extension methods. I asked why and he said: It isn't how extension ...
1
vote
1answer
92 views

Queue management project - Recommendations

I would like to develop a Patient Queue management system with online booking. In this case there are options to generate queue tokens for various departments. For example dept A will have tokens ...
2
votes
3answers
158 views

What is an good way to conditionally update a property on a collection of objects?

I have a collection of Shipment objects that I am iterating through to update another system. A property on a Shipment is a Stockroom. The target system has a unique ID defining a Stockroom record. If ...
-4
votes
2answers
190 views

What is Difference between DTO and Response Object?

What is the difference between a Response Object and DTO in software architecture? Say I want to get a list of Products in a catalog. If ProductDTO is this, how is a Product Response class different? ...
0
votes
0answers
44 views

Most performant way to store and find overlap in (coordinate, id, time interval) triples

Let me explain what I'm doing. I have a grid based on integer coordinates like (5,5), (5,6) etc., and I have an algorithm FindCells that generates a list of (coordinate, interval) tuples. These ...
2
votes
2answers
140 views

Dealing with property-level permissions in DDD and should UI or authorization influence the domain model?

Suppose I have a command like below: public sealed class UpdateExampleCommand { public int Field1 { get; set; } public string Field2 { get; set; } public bool Field3 { get; set; } ...
-1
votes
1answer
65 views

Dependency Injection and Factory resolution

In the below example, assume FooA and FooB each have constructors that have a large amount of dependencies being injected into them. If I have a class that needs to determine which IFoo ...
2
votes
0answers
56 views

Efficient BACnet device polling strategy

Example BACnet network: Some help is needed to solve a problem around architecting an efficient method of polling BACnet devices across multiple networks (i.e. MS/TP networks) where client software ...
2
votes
3answers
146 views

Abstract Factory with Pure DI

I have an application where I'm using pure DI to construct my object graph. I would like to use a factory so I can create and destroy instances of a certain class at run time. The trouble is that ...
1
vote
2answers
216 views

c# Is using the assertion method bad or not for clean code?

I'm reading Uncle Bob Martin's Clean Code and now I have a question about the code I wrote. Is using a method as an assertion method a good or bad practice for clean code? Example // Simple example ...
2
votes
5answers
200 views

Design pattern for objects in invalid states

General design pattern for object error state Consider a simple class Wallet that models a wallet. A Wallet contains a certain amount of Wallet.Cash and it is possible to take money out / put money ...
0
votes
0answers
31 views

How to implment MVVM patern for editing a shared class instance?

I'm struggling with architecture for a few related programs and libraries. Primarily with how to handle editing properties of a model class instance across multiple views and where to implement ...
4
votes
2answers
171 views

Multiple Applications, how to bring them together?

I have 7 different .NET Core applications (solutions). All supporting a different workflow such as customer request, request for change and much more. However, they do share a similar goal (that is to ...
1
vote
2answers
83 views

Unit Testing Complicated Service Call with Many Methods

I am trying to understand principle of Unit testing, Purpose, and Moq. We have complicated Service Call. The Service Call encompasses numerous Repositories and Services, with dependencies and ...
3
votes
4answers
203 views

How to Handle Item Prices Change for Reporting

I am building a Point of sales software with Sql Server 2008-R2. I am now confused about how to handle multiple items with prices change. Let us say price of Pepsi is $2.0 on 10-09-2019 but today it'...
2
votes
0answers
179 views

Onion Architecture: Should Service Layer contain DB Context?

In Onion Architecture, we have repository layer which conducts Crud Operations (simple insert, delete, update). (Applying Entity Framework with database) Onion Architecture Additionally , we have ...
7
votes
4answers
666 views

Changing States from child through parent while obeying SOLID principles

I'm trying to practise following SOLID principles. I'm a bit puzzled about following example (which is a remodel/artificial example based on actual code, which i cannot post here): public class ...
2
votes
3answers
144 views

How to model a Struct with a limited set of values that behaves like an enum?

I have a general organization problem with my code. I'm modeling DNA, and I've created a Nucleobase struct to store the "letter" of the DNA. For ease of use, I would prefer the following functionality ...
4
votes
2answers
262 views

C# How to combine types I don't have access to?

I have been developing a library with the help of another library. So what I have set up here is two classes sub-classing the library's classes for additional functionality. The problem comes in when ...
0
votes
1answer
42 views

Architecture for business functions impacting several Dataobjects/database tables

I am trying to create an example project Web API to see how "clean" I can remake the Delphi(Pascal) API we are developing on my job. I have created a solution which as of now contains 3 different ...
19
votes
3answers
2k views

Should wrappers compare as equal using the == operator when they wrap the same object?

I'm writing a wrapper for XML elements that allows a developer to easily parse attributes from the XML. The wrapper has no state other than the object being wrapped. I am considering the following ...
0
votes
1answer
105 views

Call library functions with varying number of inputs while keeping API simple

For a ASP.NET Core application, I'm using a library which performs calculations using objects that have a similar interface but their constructors use different inputs. The inputs are market prices ...
0
votes
2answers
98 views

What is a good strategy to queue incoming queries (posting to a c# controller)

I have a situation where clients are posting query requests to an endpoint (a c# controller method), and the controller takes the data they post and figures out what query they want, then calls a ...
20
votes
3answers
4k views

Never make public members virtual/abstract - really?

Back in the 2000s a colleague of mine told me that it is an anti-pattern to make public methods virtual or abstract. For example, he considered a class like this not well designed: public abstract ...