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

Are Flate compression in PDF and Deflate different algorithms?

I'm trying to make a program that produces pdf files. I've been studying the pdf format specification and specific pdf files whose format I'm trying to mimic. I found the line /FlateDecode in these ...
user avatar
  • 499
1 vote
3 answers
146 views

Array of a class or class with multiple property arrays

I have a simple question, why would I use an array of a single class over a class with multiple property arrays? Context: I have a series of calculators that extend off a base calculator. Each ...
user avatar
-1 votes
2 answers
139 views

Proper ways to manage evolving inter-communicated microservices APIs?

I'm working on a big C# application that is currently under development so we have some room for structural refactoring. The application is divided into 10 microservices, which some of them ...
user avatar
1 vote
1 answer
403 views

Namespace hierarchy in C#

I have a C# class library shared among several applications. The library is divided into a few smaller components which have dependencies shown in the picture below. Each component is placed in its ...
user avatar
  • 119
-2 votes
1 answer
192 views

Why aren't constructors atomic? [closed]

If thrown exceptions in constructors can lead to memory leaks or partially-constructed objects, then why we don't make them atomic? so neither an object nor it's local variables will get created/...
user avatar
  • 99
0 votes
1 answer
146 views

How can I allow sub-services to use concrete types, without having an ever-growing type argument list on the primary service?

NOTE: I believe I have a bit of an X/Y problem here, so please, bare with me. Also, I have trouble explaining things sometimes, so feel free to ask me to elaborate, and I will improve anything I can ...
user avatar
1 vote
1 answer
1k views

What is the idiomatic way to split code between separate files in Rust?

Coming from the world of C#, where, despite sharing namespaces, it's quite common for every class to have its own file, I find that Rust codebases seem to have a complete different sort of philosophy (...
user avatar
-1 votes
1 answer
38 views

Client side validation with Jquery - MVC C# app

I am working on a very LEGACY MVC App using C# which is built from 2009. They dont have any client side validation at all. In other words, they dont use Validation mechanism provided by MVC framework ...
user avatar
-2 votes
3 answers
314 views

Why `struct` unconstrained method fails to accept `null` as `T?` parameter

Considering example below, one observe that for reference type argument is successfully understood as nullable parameter. For value type conversion to T?/Nullable<T> fails. T Method<T> ( T?...
user avatar
  • 268
-1 votes
2 answers
114 views

How should I implement this requirement following SOLID?

Assume we had a User class which should hold references for all different kinds of request, let's say at the moment we only have 2 :RequestA and RequestB, both inherit from the base class Request. Now ...
user avatar
2 votes
1 answer
345 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 ...
user avatar
  • 129
3 votes
3 answers
1k views

Why DDD models should have private setters?

I'm learning about DDD and in many places it's stated that the domain model classes should have properties with private setters and explicit methods to change the model's state. I wonder the reasons ...
user avatar
-1 votes
1 answer
143 views

Other than the intent, is there a difference in how you implement Chain of Responsibility and Decorator Pattern?

I think it's fair to say that they are quite similar to each other. The only difference that I know is the intent. Chain of Responsibility: Avoid coupling between the sender of a request to its ...
user avatar
-1 votes
3 answers
255 views

How do I give a base class a property or method that returns different types in the concrete class?

I have a base class called FieldBase and I want to inherit from it to have different types like TextField and NumberField. I have a property Called Value which for the TextField is String and for the ...
user avatar
  • 117
0 votes
3 answers
380 views

ValueObjects exposing outside domain layer

As I learned from the DDD rules, you have to change the entity through the aggregate root. However let's say we have a value object "Address". Is it allowed to do in the AR: (I've seen this ...
user avatar
  • 183
1 vote
2 answers
41 views

Using public nested types to self contain complex POCOs for serialization

So a lot of the web says not to use public nested types unless you need the member visibility semantics (including this msdn article, even though that article hasn't been touched since 2008). For the ...
user avatar
  • 331
0 votes
1 answer
113 views

List of ValueObjects a valid thing?

Let's say we have an entity Customer which can have multiple email addresses. We create a ValueObject "EmailAddress", upon creation it checks if the address is valid. Is this concept valid ...
user avatar
  • 183
0 votes
2 answers
84 views

How should design my entities when I sometimes need only a subset of fields?

I have a class that is mapped using Entity Framework. This class has dozens of fields, and in the database there are millions of rows for this class. The class looks like this public class MyEntity {...
user avatar
  • 141
-1 votes
1 answer
203 views

How should I handle complex class construction?

I'm making a naval warfare strategy game, based on a boardgame, in C# and having difficulty finding a good way to construct my complex ship objects (I am a beginner in the language and OOP). Currently,...
user avatar
0 votes
0 answers
44 views

Which Design pattern (C#) should I use for binding / mapping unrelated models and data contracts and for service using them? Code sample below

New Design: We are porting Legacy code to C#. We have Request and Response Data Contract for each set of Business Data. These are POCO generated using Schema of External vendor. We will be creating ...
user avatar
1 vote
3 answers
384 views

Should my API return the image or path to an image?

I'm building an API in C# .NET that needs to supply the client with some data and an image. The image is stored in Azure Blob storage. Which is more efficient: Retrieving the image on the server side ...
user avatar
0 votes
2 answers
110 views

Extend the ApplicationUser class or use a Person class?

I am making a web system using Asp.Net Core with individual user accounts (Identity), and I was thinking about how I should store the users' personal information in the database. The system will have ...
user avatar
  • 131
0 votes
1 answer
134 views

In CQS is it accepted to have a coupling to another command

Consider this code, rather than hardcoding the hour when we execute a certain command I query the CQS engine and asks when it will be executed. Though now we have a high coupling to another command. ...
user avatar
  • 651
0 votes
1 answer
594 views

C# is it acceptable to create a generic class and use an enum as generic type?

Abstract The case: Application contains a lot of views with a list of data. Data views (lists of records) have pagination, filtering and sorting options. The user must be able to select a "...
user avatar
0 votes
2 answers
77 views

Designing an API where an image can be supplied

I am designing an API whereby some other system can supply an image in their POST. As such this is an API for integration purposes, with no front-end. Postman is used for testing the API. Below is the ...
user avatar
  • 109
0 votes
1 answer
112 views

Processing large number of messages in a thread-safe manner

I have the following use case and would like to implement it in a thread-safe manner. Think of a Stack Overflow-like web application. Somebody upvotes a question. A new event is sent to the message ...
user avatar
  • 747
1 vote
2 answers
165 views

CQRS: Is it an antipattern if the Command invokes a database interface which contains business logic?

Martin Fowler states that, Command module executes validations and consequential logic which aligns with every CQRS demo app that I've studied. That is to say: validation -- does this Jedi exist? -- ...
user avatar
  • 1,349
4 votes
5 answers
795 views

How can you ensure order of execution in concurrent tasks?

Here is what I am specifically doing: I have a thread-safe queue One 'write' thread constantly writes to the queue with data that comes from another service Multiple 'read' threads take from the ...
user avatar
4 votes
7 answers
655 views

When to use a class with a constructor vs using a method returning an object

I've been working in a rather large codebase filled to the brim with small classes such as class Person { public string name; public int age; public int height; } As a mainly front-end ...
user avatar
2 votes
1 answer
222 views

Dependency injection post-serialization

I'm modeling a general RPG-game-style quest system where player choices lead to certain effects. The below examples have been simplified for the sake of clarity. This is a web-based context, which I ...
user avatar
  • 38.3k
1 vote
1 answer
80 views

Does injecting ILazyLoader inside entities in EF contradicts separation of concerns in design?

Microsoft suggests to inject ILazyLoader service inside entities in order to enable lazy loading manually in EF: https://docs.microsoft.com/en-us/ef/core/querying/related-data/lazy#lazy-loading-...
user avatar
  • 121
0 votes
0 answers
122 views

How to set up login pin system

i want to set up basic login page in xamarin.forms. There is no username/password, just a simple pin so far i have 3 pages to do this Sign-up Pin page Sign-up Confirm Pin Page (re-enter pin to ...
user avatar
  • 101
-4 votes
1 answer
62 views

Calculate math function depend on N value [closed]

I have method with the following prototype : R[] = method(k,n) which : n = ordinal value 0 <n <10^9 k = math function depend on n value : i.e n^6 R = array of computed values For example : n = ...
user avatar
1 vote
3 answers
190 views

Should Source Generators be used for managing optional dependencies

Let me try to clarify my question with an example. Assume a library of some sort which has a built in logging system and it is published as Library.Core. As the maintainer you want to add a wrapper ...
user avatar
  • 121
1 vote
2 answers
2k views

How are changes propagated from the ViewModel to the Model and how often in MVVM?

I am learning the MVVM paradigm and I have seen a few different implementations surrounding the Model and how it is updated which I want to understand. My understanding of the View and ViewModel ...
user avatar
  • 117
3 votes
1 answer
421 views

CRUD is too simplistic for my usecases, how would you handle the repository pattern when using MediatR and EF Core?

I have a .Net 5 Web API project and use MediatR to encapsulate my business logic into commands and queries since I don't like to have a single CRUD service handling everything related to a specific ...
user avatar
0 votes
4 answers
343 views

How do I decouple this coupled application?

I currently have this Bot Viewer application Which consist of the application itself - the Bot overviewer, which depends on a library Bot.Core. Within Bot.core we have defined the core interface for ...
user avatar
0 votes
2 answers
122 views

Method that is aware of interface underlying type without reflection

I'm struggling with the design of a method CallSystemX() that needs to accept a parameter of multiple Types. To get around it I created an interface called IRequest to be able to pass different types ...
user avatar
  • 275
0 votes
0 answers
85 views

Exposing an event source as an interface, but where the source may expose events individually or as a collection

I am using a publish-subscribe event broker, and am constructing libraries to help people interact with this broker consistently. One of the things I would like to design is some kind of IEventSource ...
user avatar
  • 306
-2 votes
1 answer
99 views

How to implement factory pattern in following case?

I have a program which downloads web pages and then scrapes html to create domain specific collection objects e.g. ProductCollection, CatalogCollection, NewsCollection and more. The idea is to create ...
user avatar
-2 votes
2 answers
366 views

Which design pattern to use for a calculation pipeline with lots of varying rules

I'm currently trying to solve a problem with some legacy code that makes some calculations in order to find out the final value of a monetary benefit. The legacy code uses an imperative approach with ...
user avatar
3 votes
1 answer
1k views

Sharing form validation rules between backend and frontend (Having single source of truth)

I'm currently working on a web app using ASP.NET Core (C#) on the backend and Next.js (TypeScript) on the frontend. I have a lot of forms that need to be validated and I don't want to write validation ...
user avatar
  • 1,431
-2 votes
6 answers
198 views

C#, design classes to be scalable

I'm creating an inventory management system, in which the program needs to handle a lot of different equipment, with the possibility for the product owner to increase the selection, without having to ...
user avatar
  • 9
0 votes
2 answers
541 views

How to handle validation errors from API response when using repository pattern

I've got the following: Clientside C# application. Contains forms for CRUD operations. It uses an API for all data operations. Input is validated on the client, and obviously also on the server (API). ...
user avatar
-3 votes
1 answer
175 views

Proper way of implementing MVP passive in C# .net

In "MVP Passive" where a view doesn't know about it's presenter the view just raises events observed by the presenter, the presenter knows the view and its controls how should view and ...
user avatar
1 vote
1 answer
132 views

Naming for services/workers ect

I'm kind of new to this "separate your methods from models" (yes I was one of those developers). From what I understand I have to separate everything into models, services and factories. A ...
user avatar
  • 121
-2 votes
1 answer
125 views

How to sync async and await Tasks?

With threads you could use Semaphore, mutex, ManualResetEvent, etc... to sync a shared data, how do you accomplish the same thing with tasks? Essentially, if I have shared data between different ...
user avatar
0 votes
2 answers
65 views

Where to put files (interfaces) that link two independent assemblies: Authentication and Main Program

I'm having an issue with dependencies in a C# app that I'm creating. I have an assembly for my authentication process, and a separate assembly for starting up the main program once authentication is ...
user avatar
  • 1,476
-3 votes
1 answer
93 views

Inter application communication .Net

I have multiple WPF applications running different programs some of them are interconnected so one might have to start another at some stage. I need a way to communicate and share large amounts of ...
user avatar
4 votes
2 answers
242 views

How to model classes that can be extendable?

I have recently inherited a codebase which has a weird problem and I am trying to search for an extensible solution that can solve my issue. Consider I have a model class that is used as a model to ...
user avatar

1 2 3
4
5
96