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
2answers
84 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
153 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
38 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 exhibit reference equality 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
91 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 ...
-3
votes
0answers
43 views

Design OCR solution with .NET [closed]

I am new to software design & development. I am trying to develop an OCR Service using .NET Framework which can be consumed by different projects we have in .NET & other frameworks. Within ...
0
votes
2answers
89 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 ...
-4
votes
0answers
50 views

How does a partial class Form with extended class works? [closed]

This is the partial class of a Windows Form Application Form2 underlines and giving me error Inconsistent accesibility: base class 'myClass' is less accessible than the class 'Form2' public ...
18
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 ...
0
votes
0answers
17 views

Manipulating a large dataset before inserting in Azure Search

I have an Azure SQL database with 20 million + records that i need to manipulate (including joining other tables, etc) before inserting into Azure Search. The procedure needs to be reproducible in ...
3
votes
7answers
349 views

Should a base class take responsibility for wrapping incorrectly thrown exceptions that are part of the API documentation? [closed]

It is a common approach to use specialized exception types to indicate exceptional results of a method. These exception types are not considered to indicate a programming flaw, but, as I pointed out, ...
0
votes
2answers
187 views

Interface/Contracts in separate assembly?

Say I have BusinessService & domain logic as part of MyProj.MiddleTier csproj which connects to MyProj.DAL DataRepository via interface IDataRepository. I am using IOC unity container to build my ...
0
votes
1answer
69 views

Shifting from Anemic Domain Model to Rich Domain Model

I did a couple of simple projects following Anemic Domain Model . Now I am trying to do the similar type of projects in Rich Domain Model. But I am confused in implementations. Previously , I used to ...
0
votes
1answer
65 views

how to use Builder pattern combined with protected access modifier?

I'm reading a book in Design Patterns, and below is some code example used by the author. The author tries to build a html builder as (code in C#): public class HtmlElement { public string Name, ...
2
votes
1answer
182 views

Flexible (dynamic) user input vs statically typed language c#

Problem domain: There are different types of financial products and I am trying to simulate them in different scenarios. Each of the product types requires different input data. Suppose the input ...
1
vote
2answers
197 views

Is using generics like this a type of code smell?

Lets say I have the following interfaces // used by generators and other read only systems interface IRealmProvider { Tile GetTile(int x, int y); } // used by interactive realms that can be ...
1
vote
3answers
260 views

Is it good practice to make everything internal in C#?

In our solution we have a couple of projects, a project for data layer, service layer, business layer. etc. Inside the business layer, we use models to transfer data from classes to classes. Is it ...
1
vote
1answer
149 views

how can I unit test my class methods having database calls

I am working on introducing unit testing to a class in my project which is responsible for verifying customers according to a specific criteria. For clarity, let's say one of the methods in my class ...
4
votes
2answers
426 views

How to redesign a static class to make it extendable?

I'm working on a console extender project and I'm getting to a point where I feel I need some refactoring. The only public class in the project is called ExConsole, and to make it just as easy to ...
1
vote
2answers
110 views

In DDD can an aggregate also just be an entity?

I'm working on an e-commerce solution and as part of this we have concepts of things like Stores, Currencies, Payment Methods, Shipping Methods to name a few. For each of these, we have an admin ...
18
votes
9answers
4k views

Is there a better way to use C# dictionaries than TryGetValue?

I find myself often looking up questions online, and many solutions include dictionaries. However, whenever I try to implement them, I get this horrible reek in my code. For example every time I want ...
0
votes
1answer
58 views

Does reference logic belong on DAL or BL?

I have a three tier architecture API to add and remove customers. Every customer has some employees that are responsible for that customer. Those employees are located in another collection of ...
0
votes
0answers
29 views

Setup tests that use the Azure storage emulator in Azure DevOps

I have a project with the code hosted in Azure DevOps and I'd like to start using the Pipelines feature to handle the builds. My first problem is that I have a set of tests that use Azure storage ...
-1
votes
1answer
77 views

Should Specification Patterns return IEnumerable, IQueryable, or Expression?

We are implementing Specification Patterns with Domain Driven Design. Company architect also wants us to utilize Generic repository (not my choice). Currently require specification Pattern for Filter ...
0
votes
0answers
49 views

API Class Input and Paging Specification Pattern in Net Core

I was reading following website, and created a PageModel and Specification pattern. Question is should I merge these two for good practice or keep separate? The PageModel will accept following ...
2
votes
2answers
143 views

Documenting Dependency Injection Parameters

Should documentation be added for constructor parameters that are passed via dependency injection? In my current project I have decided to omit documentation to describe each of these parameters and ...
0
votes
1answer
80 views

Is making your ORM DAO a subclass of your Domain Model object a viable strategy?

I am trying to separate my domain model and associated business logic from my persistence model, particularly such that the domain model has no dependency on the ORM. One apparent way to do that was ...
1
vote
3answers
115 views

Interfaces vs concrete types in DTOs and response classes

Had a discussion that i felt i needed some external input on. Normally always use interfaces instead of concrete types (on lists, injectable services and so forth). For example in lists i just pass ...
0
votes
3answers
186 views

Is there any advantage using generic type which implements interface over direct interface usage?

When I was looking this question, a question comes my mind. Think about using an interface like : public interface ICommandProcessor<T> where T : ICommand { void Process(T command); } ...
0
votes
1answer
54 views

Authentication, Sign In mobile

I am new to mobile development. As i understand the best way to authenticate/give authorization to a user is using OAuth2.0 with the social providers as Facebook, Google ect ... When we enter the ...
0
votes
1answer
94 views

Which Software Layer should hold Pagination Information?

Which layer should hold pagination information? (Page Size, Page Number), Eg say 100 products, 5 product per 20 pages. User can type in API url layer. api/Product?Page=1&Limit=2&ColumnSort=...
0
votes
1answer
97 views

Domain Driven Design: Should Specification Pattern exist in Repository or Application level for Paging?

In Domain Driven Design, should the specification pattern for paging/pagination exist on the Repository level or Application level, or another layer? Trying to see what Eric Evans author of DDD stated....
1
vote
2answers
117 views

Ownership of conversion between static class and non static class

I have a static class that performs xml serialization. Is it better for the static class to be responsible/implement for converting objects of type foo to their proper xml representation or to have ...
2
votes
3answers
206 views

Possible alternatives to excel as business logic implementation

I just started my internship as a computer science student. The project I'm working on is web based price calculation. Previously, the price calculation have been done in a quite huge excel ...
0
votes
1answer
113 views

Which tree or graph structure to solve this problem?

I have the following interface, it defines a loadable resource that depends on other resources that should be loaded first so it can load itself: It does its job, the Find method allowing to search ...
0
votes
1answer
73 views

Domain Driven Design: Is OrderLine Detail a Nested Class of Order Header?

I had asked a question here, and someone had recommended that OrderLine be a Nested class within Order Header. Is that a standard practice in Domain Driven Design, or more one of many debated methods ...
-1
votes
3answers
106 views

How should I manage SQL Server logins for a desktop application?

I'm looking for a bit of guidance or someone to point me in the right direction. I have a C# WPF desktop application which accesses a local SQL Server Express database. The application is on a single ...
1
vote
3answers
100 views

Domain model entity layer depends on Persistance layer here?

I am trying to apply Domain-Driven Design here in this bank ATM mock app. I have 3 layers at the moment: Domain Model Entity layer (Pure POCO classes) Persistence layer (Entity Framework) Console UI ...
2
votes
3answers
294 views

Why is it necessary for every new api to be async?

I'm expressing my frustration here somewhat, but why do many new libraries only have asynchronous APIs? For example I'm creating a small utility to fetch a web page and parse some data from it. ...
0
votes
2answers
166 views

How to separate data and logic to achieve Single Responsibility Principle in C# way? [duplicate]

I'm still learning C# and best practices around it. Consider this block of code public class Counter { private int _value = 0; public void SetValue(int x) { _value = x; // ...
1
vote
1answer
76 views

Split Data logic and domain logic in POCO class?

Say for example, in this mock bank ATM app solution, I have 3 projects: UI Console Domain Model (POCO) Persistence (Entity Framework for CRUD) Domain Model (POCO): I have 2 classes public class ...
1
vote
2answers
125 views

Should an ASP.NET Web API application use Entity Framework in the API controllers?

Im a bit confused about what is best practice when working with Entity Framework and ASP.NET Web API. I am working on a project that contains a iOS/Android app and an API the app will use to ...
0
votes
1answer
83 views

Domain Driven Design // Navigation Properties and Aggregate

I'm currently making a REST API, using DDD. As ORM i use Entity Framework Core, this ORM has easy mappings for navigation properties, as you sure are familiar with. My question is about navigation ...
0
votes
1answer
64 views

Designing a system of loadable resources with dependencies

Context: For a video game, I need to load an arbitrary amount of resources which when combined would form a complete level of the game. These resources would be 3D models, textures, sound, etc. Some ...
-2
votes
2answers
102 views

C# Static & Constructor Logic [closed]

I learn C# and try to understand the logic between static and Constructor right now. One thing I need ask you about an example which I will give at below. (please ignore the quality of code or how ...
5
votes
4answers
388 views

How to keep class/file name short but still descriptive?

I've been working on a C# class library with the mindset that we will have new developers to work on it later. While I tried to keep the class/file name as descriptive as possible, the length is ...
0
votes
0answers
58 views

How to send messages in the order they were queued, while ensuring that client B does not have to wait until client A has received his message?

I have a simplified producer/consumer pattern implemented below. The code outputs: "A" 1 second delay "B" 1 second delay "A" 1 second delay "B" ... What ...
0
votes
1answer
136 views

I'm writing an application that needs to log error/ exception messages but should still continue execution if it not a fatal error

I'm writing an application that needs to log error/ exception messages but should still continue execution if the error is not a fatal error. I was thinking of making a method that returns a Task but ...
-2
votes
2answers
126 views

Separating Persistence Layer and Domain Layer [closed]

I have been reading a lot about Domain Driven Design lately, and starting to feel a little more confident, than when i first touched this topic. I'm using a Asp Core project, with class libraries for: ...
1
vote
1answer
75 views

Domain Driven Design to consolidate multiple projects

How I can consolidate multiple projects by keeping the same namespace and move them into Domain Driven Design project? We are not a software shop and our code is not an API with no intention of being ...