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
2 answers
53 views

Strategy for Chrome timing out on a Database cleanup job which takes a long time

I have a notifications app which sends users notifications. It uses a .NET core backend, an angular frontend and Cosmos DB. Within this I have an API endpoint function which is linked to a button used ...
user avatar
-1 votes
2 answers
166 views

How to avoid CRUD and layered architectures in REST backends?

I'm creating a .Net 5 API backend and use EF Core for the database part. The simple CRUD way I know: API layer calling a command or query from the application layer using MediatR Application layer ...
user avatar
-1 votes
3 answers
231 views

Design pattern for creating and scheduling tests/exams

I have an Exam class that represents an examination/test: public class Exam { public int Id { get; set; } [Required] [StringLength(maximumLength: 30, MinimumLength = 1] public string ...
user avatar
  • 63
1 vote
2 answers
235 views

Inversion of Control: Separation of concerns in a composition root

In a C# console application of mine (which uses CliFx for the command line processing), I'm setting up dependency injection using Autofac. What I've learned about IoC is that you should have a single ...
user avatar
  • 4,825
0 votes
3 answers
471 views

Are C# unit tests running independently from each other?

I'm using C# with NUnit. Let's say you have a class public class MyClass { private int classMember; [Test] public void Test1() { classMember = 1; Assert.That(classMember ==...
user avatar
0 votes
3 answers
624 views

Is it any more efficient to reuse a variable than to create a new object?

In a project I am working on we load various entities from the database, do some work then attempt to save the resulting entities. If saving the result is not successful, we return a Result object ...
user avatar
  • 29
1 vote
2 answers
1k views

C# convention for empty constructor [closed]

I know an empty method without any good reason is a code smell, but it can be required for constructors. What would be a good way to write an empty constructor among the following? class A { ...
user avatar
  • 129
1 vote
2 answers
211 views

Application made up of multiple executable programs

I am developing an engineering application (WPF, C#) that consists of a collection of other programs that perform specific engineering tasks. I guess you can think of it like Microsoft Office, however ...
user avatar
  • 21
0 votes
2 answers
376 views

Where should I put the initialization validation of a Value Object?

Hi I am making a Value Object. public class Age { public Age(int age) { Value = age } public int Value { get; private set; } } I want to check ...
user avatar
0 votes
0 answers
69 views

How to debug your collegues NuGet package

Disclaimer: This is a rather broad topic and there is probably no clear right/wrong. Still I would like to exchange experiences with experts of huge projects to learn and improve work between teams. ...
user avatar
0 votes
1 answer
46 views

Best data structure for searching best color match? (4D space)

My current color distance formula is a modified version of Euclidian distance (eDist) because with eDist I was noticing weird issues where blue could be used instead of green in some situations when ...
user avatar
  • 103
1 vote
1 answer
229 views

C# Design for database queries and commands

Currently I'm working on a project that will interact with a database. Based on my research, I would like to develop a repository class which responsability is to write/extract entities to/from a ...
user avatar
7 votes
4 answers
562 views

Use local or nested function for readability?

I found in the catalog of Refactoring by Martin Fowler, with Kent Beck book that they mention Extract Function refactoring. It is a good practice to wrap your related code into local functions to ...
user avatar
  • 179
1 vote
1 answer
97 views

Does it make sense to have a facade centralizing events too?

From my understanding a facade is a class with the sole purpose of simplifying the use of a specific system/module behavior (its methods). It should not contain any relevant logic of the underlying ...
user avatar
1 vote
2 answers
77 views

c# template method pattern design question

I'm currently in a situation where I have multiple derived class types(just one is shown in the example below) that need to apply some logic before and/or after calling a method implemented in a ...
user avatar
-2 votes
2 answers
908 views

Measuring async/await overhead

A while ago I read an article stating that overhead of an async/await call was around 50ms. More recently I read an article that it was around 5ms. I was having a discussion about whether we should ...
user avatar
  • 355
4 votes
4 answers
438 views

How name public method that relays to abstract methods of its children (c#)

I've run into the following situation multiple times, and in every case have struggled with the naming. I want a class to force its children to implement a method, but I want the parent class to be ...
user avatar
  • 1,476
2 votes
1 answer
162 views

Event Driven Architecture how should channels be used

I'm using event driven architecture, to perform realtime signal proccessing and to provide independent metrics. I decided to use a redis cluster to act a cache and a message bus. I'm a bit confused ...
user avatar
  • 335
2 votes
0 answers
24 views

Breadth first event synchronization based on a frequency or time series

I have an interesting and problem I'm facing. I'm trying to maintain a set of metrics independently based off of a time frequency. Note: This is a simplification of the problem I've omitted pieces of ...
user avatar
  • 335
-1 votes
5 answers
289 views

Designing Entity Objects in OOP

I am newbie to programming and I am confused how to design an entity objects/classes. For example I wanted to create an animal kingdom in my application. Do I need to create a single Base Class (...
user avatar
  • 21
0 votes
3 answers
260 views

What is the proper way to throwing an exception?

I'm currently make a Helper class that can be used by multiple team members. Helper class uses third party API. And I have a question about that handles exceptions in the Helper class. https://docs....
user avatar
  • 61
4 votes
2 answers
1k views

Alternative To Generic Methods where Type is known at runtime

I've written a class that synchronizes a table between two databases using Dapper. The public and private Methods in the class are generic and the generic parameter is the POCO class that is being ...
user avatar
  • 379
-1 votes
1 answer
895 views

How can I orchestrate multiple business tasks?

I have a WebApi backend with a Blazor WASM frontend. The application is split up into 3 main parts. Core, Infrastructure and Presentation. Basic onion architecture structure. Core.Domain Domain ...
user avatar
0 votes
1 answer
330 views

Web Components/Redux with .NET Core MVC viable?

I'm currenty building several new themes using NopCommerce, a .NET e-commerce platform using the MVC architecture. NopCommerce exposes a lot of services to you for communicating with the db, and is ...
user avatar
1 vote
3 answers
662 views

Is it bad practice to do additional work in IAsyncEnumerable generator method?

Imagine you have to process each row in a large table. For every single row you have to download some data from a web service and store it in a different database. Loading all rows at once into the ...
user avatar
  • 13
2 votes
4 answers
312 views

Is it common practice to declare exceptions in a library that won't be thrown or caught anywhere within that library?

I have a very basic library that serves the purpose of collecting some useful but simple pieces of code. Like for example a Percent struct or functions like ToDegrees() and ToRadians(), just to give ...
user avatar
-2 votes
2 answers
282 views

Why use private access modifier if we need to access private variables anyway?

Everywhere is said that a private member can only be accessed from inside the same class, but at the same time, we can access the private member using getters and setters, therefore my question is: ...
user avatar
0 votes
1 answer
56 views

Index all fields of json documents in a desktop app without server or service

We have a .NET Core application that works as a datawarehouse and we store our entities in json documents that we regroup by projects. Usually projects would easily have 300k json documents with 50 to ...
user avatar
  • 145
1 vote
1 answer
142 views

Synchronizing Multiple Local SQL databases with Server

I'm trying to understand what general mechanisms and/or concepts are available in SQL database last to synchronize local. Here are my inputs and requirements. Multiple clients have a full copy of the ...
user avatar
  • 379
0 votes
3 answers
161 views

Solutions for polyadic functions/methods

In the book Clean Code, Robert C. Martin says that we should avoid polyadic functions (functions that contain four or more arguments). One of the solutions presented by him is the use of objects as ...
user avatar
-2 votes
2 answers
143 views

Leave method (return) based on pass/fail outcome of another method (C#)

I have a WPF application used to execute logic that tests hardware (i.e. reads sensors, amps, voltages, etc.) Each individual test runs when a "Test Device" method is called. I need to be ...
user avatar
0 votes
1 answer
74 views

Recommended way to use a python backend from a c#-application

I have an old windows forms gui used to control a custom measurement system. Originally, it handled acquisition, calculating, database handling and presentation of measurements. Now, because of some ...
user avatar
  • 3
0 votes
1 answer
155 views

DDD best practices ValueObject immutability when using composition

Pretend I have entities A, B, C, D. They each have a structure as follows public class A{ public IEnumerable<B> Bs {get;} public IEnumerable<C> Cs {get;} public IEnumerable<...
user avatar
3 votes
3 answers
783 views

Use inheritance to make single child, smaller

We have a relatively big class. One of my colleagues thinks we must split this class into a base & child class to make it smaller and cleaner. On the other hand, I believe when we know this parent ...
user avatar
-3 votes
1 answer
71 views

How does a site API determine the difference between a user and program request in a browser?

So this is in regards to scraping yes; no language in particular. Some sites allow you to see a JSON modal if you pull it directly from a web browser. But, at any notion a program is used, immediately ...
user avatar
0 votes
2 answers
502 views

Patterns for returning messages/results from business logic to UI

Cross-posting from SO. Is there a name for the patterns used send messages/errors and results through an application's layers from business logic/database to the UI? What is the modern way? For ...
user avatar
  • 379
0 votes
1 answer
101 views

Monolithic view model MVC

Currently working on a legacy app. One section deals with generating "reports", each which share some common subsections, that are based on strongly-typed razor partial views. The largest ...
user avatar
1 vote
1 answer
46 views

Deisgn Pattern: How to map UI requests to Controllers to Services?

I'm learning about writing WebApi design patterns. I am trying to create a simple CRUD web app with ReactJS UI and C# .NET CORE webapi with sql backend. Articles show that specific Repositories are a ...
user avatar
  • 21
1 vote
4 answers
169 views

Displaying exceptions

I read/watch about Uncle Bob's clean code and when he talks about exceptions he suggested to have a well named exception over a description which make perfect sense for the programmer, for decoupling ...
user avatar
0 votes
2 answers
216 views

Why/When do we need to call an async method from a sync method?

It is my first question here so I hope I'm not doing a mistake. I see a plethora of questions in SO that people ask "how can I call an async method from a sync method?". Given my little ...
user avatar
  • 109
1 vote
3 answers
526 views

Offline user authentication

One of our customers had a pen test performed on our application this week and let's just say it didn't go well. The main issue they have is that user authentication takes place on the client, rather ...
user avatar
0 votes
0 answers
118 views

How can I use the Factory pattern and expose my factories to consuming code without introducing transitive dependencies on the constructed types?

I have a C# class called FileTransferManager. Previously it took some parameters such as a username and password to connect to a FTP server. However now I have an additional requirement to support ...
user avatar
  • 491
3 votes
3 answers
449 views

How to decouple chain hierarchy project dependency by dependency injection? (C# .Net Standard)

I'm working on decoupling a Xamarin (.NetStandard) solution. It was using DryIOC container but I didn't see the IOC structure from the dependency, as the projects are still tightly coupled. Three main ...
user avatar
  • 133
0 votes
0 answers
86 views

c# class structuring and appropriate coding techniques

I have 2 classes that share some properties public class SportsUser { public string errorCode { get; set; } //the sportsuser and SportsAdminUser is from a different database hence the long and ...
user avatar
  • 11
0 votes
1 answer
72 views

Thread-Safety with Enumerable collections and copies

Imagine I have an interface IHeapObject: interface IHeapObject { string Id {get;} SomeEnum Type {get;} } and it's implementation HeapObject: class HeapObject : IHeapObject { public string ...
user avatar
  • 11
2 votes
5 answers
555 views

All the properties of a domain object should support NULL value?

Imagine you have an application with the domain object User: public class User { public int Id { get; set; } public string Name { get; set; } public string Surname { get; ...
user avatar
  • 59
0 votes
1 answer
492 views

What would you name the different DTOs for the methods "GetUser" and "AddUser"?

I have a web service with the methods GetUser and AddUser, and some DTOs (Data Transfer Objects) GetUser: retrieves user information, as a DTO called UserGet DTO AddUser: takes a DTO called UserAdd, ...
user avatar
  • 111
1 vote
1 answer
118 views

C# - Menu Implementation - Help writing it in a testable way

The Question: I'm developing an app in C# and am currently designing a menu which contains submenus and needs to be different depending on the category of the user. I've written the code but am ...
user avatar
  • 149
0 votes
0 answers
112 views

Is it a bad practice to have a class with a namespace that goes "out" of it's project name?

I have a solution with multiple projects, lets suppose there's one project with the name Company.Name.Foo.Bar. If I declare a class inside the project Company.Name.Foo.Bar but with a namespace Company....
user avatar
  • 329
0 votes
1 answer
211 views

How to implement Inter-Process Communication(IPC) at the local machine without parent-child model?

I'm trying to exchange some small data between my two apps. This two apps located at the same PC, so all exchange happens inside this machine. At first, I thought maybe to use sockets for it, cause I ...
user avatar

1
3 4
5
6 7
96