Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c#]

C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform

-1
votes
1answer
70 views

Where should domain events be added: in entities or aggregate roots?

I'm designing the base classes and I don't know if I should add the field 'domainEvents' to the Entity class or only to the AggregateRoot class. I must add the code for add and remove events in ...
0
votes
1answer
143 views

DDD - How to do informative validation (specifically on entity creation)?

For my domain entities currently, all validation errors cause exceptions to be thrown. I don't like this as it doesn't allow me to compile all validation errors before exiting a method. I'd like to ...
0
votes
0answers
74 views

Storing self-expiring items in redis and getting all of them

I need to place some data into redis so that each element has a sliding expiration (say 60 seconds each). I also need to be able to get a list of all elements that are currently in Redis. Initially ...
0
votes
1answer
93 views

Wrapping WCF client with Stream for disposing

I need to consume data from a WCF service, which pipes it through a stream. The data itself is contents of an archive file, so it needs additional logic, which I am splitting off into a separate class....
-1
votes
3answers
192 views

What is a CRUD system?

I am learning Event Sourcing in my spare time. I see lots of references to 'CRUD type systems' online. I understand a CRUD type system to be: 1) A database driven system (website or application) i....
2
votes
4answers
354 views

What are the benefits of local instance variables?

I have a tendency to invoke methods directly on a new class instance like this: new Person().GetAge() when I don't need the instance of the class (here Person) after the invocation. However, I have ...
0
votes
0answers
31 views

Should I use the same class for the configuration and the runtime object representing the same entity?

I am building an reporting application. The database already exists, is populated by an other system, and contains an 'cuurent balance' table, with columns CustomerId and CurrentBalance In the ...
1
vote
2answers
92 views

Performing serial communication in constructor to initialize an object

I have a class UnitInfo which represents a collection of unit information with methods to get the unit information in a structured way, such as a specific encoding, etc. This unit info consists of ...
0
votes
1answer
143 views

Should I avoid nested generic collections?

I recently came across a dictionary with lists for values passed as an argument: Demo(Dictionary<string, List<string>> arg) It got me thinking---normally I would abstract any list or ...
1
vote
2answers
196 views

How to interpret Dependency Inversion Principle

I am working on trying to understand the SOLID object oriented design principles. I was able to get the "SOL" pretty easily, though "L" required some hand holding because I am bad at definitions. I ...
1
vote
1answer
122 views

Do we really need SerializableAttribute?

I understand we need it to mark a class whose objects can be serialized, but do we strictly need this for behind the hood logic to work? We could just serialize the object using necessary methods. On ...
0
votes
1answer
133 views

Time-based Task scheduler engine

I am working on an enterprise level application. I have an event table in the database. I need to update my events' states in the database on a precise date and time. There may be 200 milliseconds ...
1
vote
3answers
240 views

Should it be a claim, a role or a policy?

The distinction between roles and claims is that roles describe a set of users and claims describe a property of a user. So there can be a role "Administrator", but there can also be a claim "...
3
votes
2answers
129 views

Separating Domain Object and Data Models

I looked through a lot of articles, blogs, and SO topics about separating domain object and data models. Almost every answer said: You should have separate classes for the domain and data persistence, ...
0
votes
2answers
257 views

Unit Test a CRUD Controller MVC

I have looked through answers related to this but they don't seem to solve my problem. I am fairly new unit testing and testing as a whole. I just finished a small web application using ASP.NET Core ...
4
votes
1answer
192 views

How to have multiple source copies of a dependency in a C# git project?

In our company, we develop information system software in C#.NET, which has client-server-module architecture. Module project does not depend directly on server/client project, but only on shared ...
1
vote
3answers
86 views

Catch statements with other Business Logic in Parsing Files

I am writing a simple program to parse a text file and place into Generic List. Sample Text: 1,Joe,CA,58,2 2,Matt,TX,63,5 Sometimes, there may be an error, with missing data in the file 1,Joe,CA,...
0
votes
1answer
114 views

How should I separate File Parse Classes?

I want to understand different ways to object design classes. I have three different classes. Generally I am creating a file parser. The classes: CustomerData - which shows text Data Model. A File ...
3
votes
2answers
148 views

What's the best way to design batch job type processing

I'm working on a portion of an ERP system where I need to process data in a way that's similar to a series of batch jobs, and I'm struggling with deciding the best program architecture to use. I'm ...
3
votes
4answers
128 views

How to properly decide what is the appropriate rounding off error for a mathematical function?

In the space of 3D geometry, I need to compute the magnitude of the cross product of two Line3D because I want to check whether these two Lines are "parallel" to each other. Line3D is consisted of 4 ...
8
votes
2answers
885 views

Why is DateTime.Month an int?

In C#, the DateTime property Month has a type of int (a 32 bit signed integer) yet its range will only ever be 1-12. What are the reasons the C# team chose int over a smaller numeric type such as byte(...
2
votes
2answers
189 views

What is the correct usage of the IEnumerable interface in C# to deal with collections?

When I am working in ASP.Net MVC or WebApi, I often find myself creating Views or return data structures that include 'List<>'s of objects. Meaning that I have a list of data objects that I want to ...
26
votes
5answers
7k views

Should I check if something exists in the db and fail fast or wait for db exception

Having two classes: public class Parent { public int Id { get; set; } public int ChildId { get; set; } } public class Child { ... } When assigning ChildId to Parent should I check first if ...
1
vote
0answers
67 views

Hierarchy of models while designing a client for a RESTful service

I am trying to write a client for a restful service. I am confused in designing the models. Below are the details: I have a Model named UnicastMessageRequest, it's definition is like this: ...
41
votes
13answers
10k views

Is it unreasonable to expect Any() *not* to throw a null reference exception?

When you create an extension method you can, of course, call it on null.But, unlike an instance method call, calling it on null doesn't have to throw a NullReferenceException -> you have to check and ...
3
votes
1answer
179 views

On layered architecture with ddd

I've been working on an architecture, trying to learn more about DDD, layered architecture, etc. Here's what I have: Domain Here I have my entities, the classes that directly map to a database table....
1
vote
1answer
97 views

Succinctly naming an Either object

I have an object that wraps an Either<T,T[]>. It can only be either a single instance of T or an array of T[] but I don't know at compile time. What do I name the class, and what do I name an ...
1
vote
5answers
595 views

Limits of Defensive Programming acknowledging that Exception Handling should be avoided

I've read Defensive Programming vs Exception Handling? and if/else statements or exceptions, but none contain something relevant to what I'm searching for. Taking into account that exception handling ...
1
vote
1answer
71 views

Data Integration Design Using Microsoft SSIS

I am working on a data integration project, where I need to extract data from oracle source and load it to XML file. The requirement is to get the list of customers and foreach customer create an xml ...
-2
votes
2answers
195 views

Is an inline temporary variable recommended in a return statement?

I have method a the returns something like this: List<Customer> customers = repository.GetCustomers.Where(x => x.IsActive); return customers; Visual Studio tooling is suggesting an inline ...
12
votes
4answers
581 views

struct with nonsensical default value

In my system I frequently operate with airport codes ("YYZ", "LAX", "SFO", etc.), they are always in the exact same format (3 letter, represented as uppercase). The system typically deals with 25-50 ...
0
votes
1answer
139 views

Implementing CQRS inside a Microservice

I am considering a CQRS refactoring process. It is more of a learning exercise in my spare time. The use case is similar to a price comparison website where a user enters their details for a ...
2
votes
3answers
221 views

Should a class constructor ever create objects of other classes? [duplicate]

Is it ever good or bad to have a constructor create new instances of classes that it needs versus passing in a reference that you want the new class to have ? So basically it's the difference between:...
-1
votes
1answer
121 views

Separating common logic into an interface

I order to achieve the DRY principle I want a functionality that logs processing time of some other functionality for example for each group of classes with a Base class. So the most logical way is ...
0
votes
0answers
49 views

Structuring dependencies for .Net core across Nuget packages

I am working on a microservices system in c# (.Net Core) where for simplicity we place each microservice in it's own repo. Some services are very generic and some are very similar (although for ...
4
votes
3answers
539 views

Mapping API models(DTOs) to rich domain models

How to implement HTTP's PUT that works with child collections when using DDD's rich domain models? Let's say we've got an aggregate root with a nicely encapsulated collection of items: (I omitted ...
0
votes
1answer
87 views

Dealing with child collections updates in Web API

Let's take some classic enterprise example: Order and OrderItem public class Order { public Guid Id { get; set; } public ICollection<OrderItem> Items { get; set; } } public class ...
0
votes
1answer
83 views

Implementing dynamic Model properties by country

I'm having a dilemma where I would need to implement a better way for our Project Model with dynamic property depending on the country. So what happen in our application we have dynamic fields for a ...
0
votes
1answer
212 views

How to efficiently solve “close” players/items in an online game without iterating through all of them?

I have an online game server that works as follows: Once a player connects, he is in one of predefined sessions (consider them physical location, e.g. Island, Underground location, etc.). Then ...
1
vote
1answer
91 views

DDD Relations between child entities / value objects

I'm new to DDD and trying to wrap my head around it by writing a prototype for an application (Core-Logic-Layer). My domain model looks like this atm. (I leaved out parts, that weren't necessary for ...
0
votes
2answers
167 views

Complex interfaces in multilayer project

In my C# project I need to swap data providers in the future so I have created interfaces to build future providers off of. But this is the first time I have worked with interfaces that are "complex" ...
4
votes
3answers
230 views

Decoupled design using static interfaces

Now first I want to mention that I am not quite sure what is the term describing the issue at hand but I hope that I can illustrate it with some code. Problem: A shared class library defines an ...
1
vote
1answer
171 views

Entity Framework - extending OR injecting services into DB Context

I fear I'm asking a somewhat silly question, but I'm now completely lost as to which principle I should follow. To my understanding - in terms of Single Responsibility Principle it's best we don't ...
0
votes
1answer
55 views

Is changing the domain according to the user privilege on specific fields considered as anti-pattern?

Is changing the domain according to the user privilege on specific fields considered as anti-pattern? My case: I have Schedule Entity (aggregate root) like this: public class Schedule : Entity<...
3
votes
0answers
752 views

Unit Of Work with multiple database context

I have created an application (net core 2 & ef core) with Unit Of Work and Generic repository pattern. I used to have one database context but due to some business logic I had to create a second ...
0
votes
0answers
25 views

Should I use “Map” or “Select” for new functor-like operators in C#?

I'm designing a type in C# that will be used as an algebraic type in a functional style, but is not a collection type and does not implement IEnumerable. If this type is a Functor, should I name its ...
-3
votes
3answers
381 views

Shouldn't cost be good reason to migrate to .Net from Java

I have a RESTful services developed using Java Spring framework. It's not a huge application, around 12K lines of Java code. Front end is in Angular and DB is No-SQL world. Recently I came to know ...
0
votes
1answer
65 views

Design Pattern for Classifying a set of Data

I am working on some legacy code that involves Orders placed by Customers. There is a new requirement to classify each Order by Business Unit. The Business Unit Name will be stored in a new column on ...
-1
votes
2answers
125 views

Handling logging when there is no internet access

I'm developing an application that handles sales for multiple clients, when the client sells a particular item, that information should be send to the admin. The count of each item sold and the item ...
0
votes
2answers
123 views

In Entity Framework how do I wrap a database call with a call to another service and ensure they're always called together?

I have an entity framework model called Employee. Whenever I request a list of all Employee rows I first want to make a soap request to get any new employees from another system and update the sql ...