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
68 views

Where to put the reference to Application Insights in an application designed with the Clean Architecture template?

We are implementing an application by trying to follow the Clean Architecture template for C#. Our application is an ASP.NET core web api and we want to implement the observability for that ...
-3 votes
0 answers
48 views

interpolate between two sets of data [closed]

I have an object that stores the dimensions of a sheet of material (length, width). I'm working on a project that involves machines to cut this material. When calculating the speed and/or cost at ...
3 votes
1 answer
114 views

Can the read api receive events that the write api does not receive or raise?

Say I have a read API and a write API: MyApp.Write.api MyApp.Read.api Both API's handle integration events from other apis/microservices. Say I had certain integration events that only need to be ...
-1 votes
0 answers
55 views

Design for adding an additional version of a service to live side by side with the first one

This is a follow up question to this question: Class inheritance design with protected methods and run time base handlers I want take a step back from the previous question - that one was an issue ...
-2 votes
3 answers
151 views

Class inheritance design with protected methods and run time base handlers

Using C#, I got a class called BaseConfigurations which handles CRUD operations. This class also contains a protected method which is used inside the CRUD handling methods: public class ...
1 vote
5 answers
434 views

How are strings simultaneously objects and primitive data types in C#?

In C#, strings can be used like objects with methods, properties, and other features of objects. At the same time, strings are treated the same as primitive data types like int or float in numerous ...
2 votes
2 answers
449 views

Can a query handler (not repository) access a web service?

Say I have the following class, which maps to a database table: public class Person { public Guid Id {get; set; } public string Name {get; set; } public DateTime DateOfBirth {get; set; } ...
0 votes
2 answers
56 views

EFCore In Memory repository Unit Test of Encrypted data

I have in project linq repository unit tests. [Fact] public async Task Get_FromTreeEntitiesUnsorted_RetunsOrderByDescending() { //Arrange _contextReadonly.Entity.Add(new ...
2 votes
2 answers
234 views

Custom messages to UI from DAL?

I have an Asp.net MVC application and sometimes I want to give a descriptive error message to the user, but the condition of it is discovered at the Data Access Layer (DAL). So for example, I have a ...
0 votes
0 answers
36 views

Avoiding conflicts with Microsoft Two-factor authentication across multiple web applications help

I'm designing a web application and using Microsoft's out of the box Identity and its default Two-Factor Authentication (with Asp.net core MVC and .NET 8). While setting up and testing the 2FA ...
1 vote
0 answers
93 views

Options for C# machine to machine communication [duplicate]

I’m evaluating different options for communication between C# applications. My requirements are: Central server where clients connect Persistent connection, server should know when clients connect/...
1 vote
1 answer
89 views

Storing uploaded images in Azure

I am building a web application with the React + ASP.NET Core template. The application will have a form for uploading recipes, including an image. I am hosting the application as an Azure Web App (...
0 votes
1 answer
157 views

How to organize "master" data VS "working" data in MS SQL

I have this survey software that I'm writing and I'm wondering what would be the best design for my requirement. I'm going to simplify it as best as I can. I have these entities: class Survey { ...
-2 votes
1 answer
137 views

Resorted to Unconventional( i.e., hacky) "circuitous" programming code techniques when using populating a list of C# Action Delegates via a for loop [closed]

AWS Amazon.S3.Model.PutObjectRequest is merely a 3rd-party AWS Data Transfer Object (DTO) / Plain Old C# Object (POCO) type that can be used to build a request that can be used to send requests to an ...
1 vote
1 answer
272 views

When shall one ignore the absurdity of some code diagrams?

I wrote a relatively small user interface for Unity, whose job is to ease working with parts in a scene, i.e. show/hide/toggle objects to reduce clutter. Long story short, I refactored it to use their ...
5 votes
4 answers
1k 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 ...
17 votes
4 answers
4k views

How should I store readonly data to deploy with my application?

I'm developing a desktop application, and this application requires some information to run, but it doesn't change any of this information (the data must be loaded on every execution of the app, but ...
-2 votes
1 answer
123 views

How to go about version numbers in a C# solution

My current situation: I would like to apply this to a solution containing multiple projects (one executable and different libraries) in C#. Additionally, I have a project that packs the executable, ...
6 votes
5 answers
5k views

Why is C# considered a statically-typed language, although it contains keywords such as `dynamic` and `var`?

C# is considered a statically-typed language. However, it contains keywords such as: var, which infers the type at compile time, and dynamic, which determines the type at runtime. Is this a ...
7 votes
1 answer
731 views

I need to be able to adapt my type to theirs, and theirs to mine

I have a situation where I have an external library. In short, I need to be able to adapt my type to theirs, and theirs to mine. The library has a collection like so: interface IExternalCollection { ...
0 votes
1 answer
292 views

Domain Modeling / Architecture

I'm experimenting with some projects at the moment and I am stuck trying to decide on the correct approach to this question. Given a simple architecture like this consisting of Domain - (Person and ...
0 votes
1 answer
71 views

How to create QueryBuilder to work with concurrent requests

I need assistance with the QueryBuilder that generates OData query. Following is my implementation and it approach has couple of issues If user forgets to SetRootTable then it will cause serious ...
2 votes
1 answer
121 views

Algorithm for finding all combinations with constraints

I'm looking for a way in C# that finds all the possible combinations with constraints. I've got a list of machines. The machines have capabilities and limitations. I also have a document that defines ...
1 vote
2 answers
378 views

C# - Generic Configurable Condition checker at Runtime - Achievement System

I'm writing a "generic" achievement system for my MMORPG project, it needs to be friendly & efficient for my game designers (without having to write code to add new achievements). If anyone got ...
0 votes
2 answers
145 views

Should entities always be simple and mapped?

I am told everywhere that entities are only to represent the data structure, then entities should be mapped to a model and then the model possibly to a DTO. The other way is similar, DTO -> model -&...
0 votes
3 answers
478 views

Lockfree customer producer problem

We have following class: class ProcessStore { ConcurrentDictionary<int, MyDisposableClass> _processes = new(); bool _disposed; void Store(int Id) { if(_disposed) { throw; } ...
1 vote
1 answer
279 views

Should snapshot tests compare against stored test data or data from a database?

I have a method GetReportAsync that takes one XML and generates another: public async Task<string> GetReportAsync(string id) { // Get Order.xml from a file database var order = await ...
0 votes
1 answer
315 views

Observer pattern using static events

I'm working on a game prototype: I have a Cell class which, given a mouse click on its collider, can raise an event that should be listened in two different modules: Camera and UI. The Observer ...
3 votes
4 answers
278 views

Sorting a sequence according to a hierarchical set of rules

We are producing configuration files for a production system. The configuration files have a dynamic set of variables. Optional values and other values that only need to exist based on other values. ...
22 votes
4 answers
11k views

How should I provide additional information about an exception?

Everytime I need to provide additional information about an exception I wonder which way is actually the right way of doing this. For the sake of this question I wrote an example. Let's assume there ...
2 votes
3 answers
225 views

How to retain the concrete type when writing base-class-oriented code?

A scenario often arises when attempting to make some existing code reusable. I introduce an interface to represent the commonality between some new feature I'm implementing and some existing ...
1 vote
2 answers
451 views

C# Source Generator : which way to go for a simple GitHub Community Project

CONTEXT My project is about implementing the "conventional method for house-energy-efficiency assessment" in France (120 pages). I want to provide a strict yet easy to use API to this method....
0 votes
2 answers
515 views

Best practice ASP.NET MVC share code with Web API

I'm trying to develop an ASP.NET MVC-application with an additional Web API. To reduce code-duplication, I'd like to share as much code as possible, but with the possibility to differentiate between ...
2 votes
3 answers
205 views

Displaying a list of similar but different objects without resorting to type checking

I'm creating the UI for a "Point of Sale" type page. You can add orders, grouped orders, and custom items to your transaction, and it should display these in a list so you can see what you ...
1 vote
4 answers
374 views

What's the alternative to trying to inherit static methods?

I know you can't inherit static methods, and it seems the consensus is that if you feel like you need to, you're doing something wrong. However, I don't know what the alternative is in my case. Please ...
4 votes
3 answers
890 views

Does it make sense to to abstract serialization/deserialization?

Serialization and deserialization in .NET applications can be achieved using several libraries, e.g. Newtonsoft.Json System.Text.Json Assuming I'm developing a new application where I want to use ...
0 votes
1 answer
281 views

Architecture solution for scalable crawling

I have the following requirements: a list of queries (rather long list ~ 100K - 1M items or even more) that I need to perform in a certain period of time and the execution time must be predictable. ...
1 vote
1 answer
64 views

Reserving Unique, Sequential Group Numbers in ASP.NET Core with EF Core and GraphQL

I am developing an API backend using ASP.NET Core Minimal API (.NET 7) with Entity Framework Core, HotChocolate (for GraphQL), and a Microsoft SQL Server database. I've encountered a specific ...
1 vote
1 answer
85 views

Persisting data in a mobile app backed by a rest API back-end, advices [closed]

So I am working on this mobile application using MAUI, which is backed by a Rest API in ASP.NET Core. I want to be able to use the app offline, and the user can create/edit some data. This data is ...
7 votes
3 answers
5k views

Why does C# not allow scope-local using Directive?

One thing I do not get with C#'s using Directive is why I can only "use" a namespace at file level, and not within any arbitrary block scope. (using namespace x; of C++ does allow this and ...
0 votes
1 answer
120 views

Generic message broker based on WCF

I apologize in advance for a long-read question, but i'm hardly stuck here and don`t how to ask for help using fewer words. I need to implement a middleware service which should be placed between two ...
1 vote
2 answers
1k views

Multiple API calls potentially spawning multiple Websockets - Threading vs Async

I am designing a program with the flow as outlined below. Note, these are all network calls, there is no system I/O (hard drive). Initially, multiple independent API calls need to happen - they don'...
0 votes
1 answer
214 views

Asynchronous execution queue in C#

I'm trying to a create a "Task Queue" that has the following behaviour. Work is added via a Func such that the task is only started when the item is popped off the queue (no when it is ...
0 votes
1 answer
1k views

Generic Repositories with different IDbConnections

I have two different connection strings for two different databases. My first database has 2 relational tables: -First table has some default fields,among which average on UI, and some additional ...
2 votes
2 answers
811 views

GetOrCreate method for a database operation

I have read this thread: Is it bad coding practice to create something in a get if it does not exist? But, my question involve a method which gets a record from a database or creates it if it doesn't ...
0 votes
2 answers
521 views

What if a Repository needs to apply Business Logic to load an Aggregate?

I have an aggregate User and the user has a Score. The Score of a user is calculated by queriying a bunch of different tables and running through (often very large) result sets applying some business ...
5 votes
4 answers
16k views

Is it possible to infer the the generic type from a generic method?

I'm making an HTTP API client class. I want a Perform() method which takes a request object and returns an obejct that is expected from the API. So a PostRequest object will describe how to get a ...
1 vote
1 answer
736 views

MVVM viewmodel to view correlation in adaptive UI

I am making an mvvm application for the uwp platform and I am looking for advice on the following matter. Take for example the windows 10 e-mail application, which when full screen displays both the ...
-3 votes
1 answer
102 views

Screen share with Windows Remote Desktop Services

I need to create a WPF application that gives me the possibility to connect to other computers in the same network. I'm looking into Windows Remote Desktop Services, but it seems like it doesn't have ...
14 votes
6 answers
6k views

Why is it necessary to mark classes as not inherited from? Can't an optimizer automatically detect that virtual calls are unnecessary?

In C# and C++, an apparent trend is in place to reduce / avoid inheritance: C#: "Sealing types can improve performance." https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/...

1
2 3 4 5
99