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

2
votes
1answer
551 views

C# design to force the virtual method to be called from the override, or something similar

We can do something like this: // in base class protected virtual void Init(){ //do stuff that all objects need to do } //in derived class protected override void Init(){ base.Init(); // if ...
1
vote
1answer
90 views

sequential command processing with an async io cloud upsert

We are new to c# and still trying to grok the async idioms. We have a windows service that requires us to iterate a list of results queried from a PC database to feed the parse cloud server (which ...
-2
votes
1answer
71 views

Should I use a strongly typed programming language for an integration with a JSON RPC 2.0 API?

I have to integrate with another company's API, which they unfortunately decided to write in JSON RPC 2.0. If you're not familiar with JSON RPC, it's a lightweight RPC protocol that defines a ...
1
vote
3answers
293 views

Easy to maintain ways that helps code readability in C#?

Say we start with a base class that states if an object is valid or not (included one interface and two child classes for discussion purpose), like: interface IValid { bool IsValid(); } public ...
1
vote
1answer
141 views

Am I waiting for the new C# 8 'record' feature?

I'd like an immutable class, or rather a class whose properties are initialised (whether they have public/private setters or not), in the constructor: public class MyClass { public string ...
2
votes
2answers
130 views

Pattern Matching in OO code

I have a situation where I need to model objects that don't share common attributes but represent same logical entity. Now, based on their type they will have different attributes (properties). To ...
2
votes
1answer
183 views

Net Automatic Serialization vs Custom Serialization Difference

In C#, what is the difference between Automatic serialization and Customer Serialization? Also what is Reflection? I know this stuff is not simple, if someone can explain in lay man's term, that would ...
5
votes
1answer
332 views

Is there a thing as “too many threads”

I wasn't sure if here or SO was the right place to ask this, but here goes anyway. So I want to improve a system that is currently running. It has services and many stand alone apps, but none of ...
5
votes
2answers
153 views

Is it worth implementing Entity Framework when calling a single stored select?

I'm currently building a web application for my enterprise level business internship. This web application will track data from three different sources: a DB2 database, a SQL Dynamic database, and an ...
0
votes
6answers
217 views

How to restrict method's parameter to the class, where the method is overridden

I have quite simple class hierarchy: public class Base { //... public virtual void AssignFrom(Base baseObj) { //DoSomeStuff } } public class DerivedA : Base { //... ...
1
vote
1answer
135 views

How to handle a large amount of very specific use cases

So I'm writing a program that runs quite a few different tests. Which tests are ran varies based on which UI elements are selected by the user. For example, on one form I have 7 radio buttons and 6 ...
0
votes
3answers
545 views

Repository Pattern and Joined Queries

In conjunction with Unit Tests and Dependency Injection I (and my primary coworker) are exploring Repositories. However we cannot come to a solid plan of action for implementation. In a basic ...
0
votes
0answers
46 views

Provide extension points to library

I have a library that provide some common logic for reading settings from multiple sources. the library uses a chain of responsibility to populate instances of objects that will contains the settings ...
0
votes
0answers
248 views

Update Redis Cache in real time in microservice

I have 2 microservices api in dotnet core microservice1 -------------Database1 ---------------------users_table (gets list of all users) microservice2 -------------Database2 ---------------------...
2
votes
1answer
71 views

Persisting domain state without exposing underlying provider(s)

Working on a DDD application where I need to persist state. Here's a very simple example: public interface IRoot { public int Id { get; } void UpdateValue(int value); } public interface IState {...
0
votes
1answer
138 views

Properly named factory method vs chain of rules

I have a requirement to have a component that will check input against some rules in a strict order. The order of the rules is defined by the business. To keep example code simple, I'll try to define ...
0
votes
1answer
59 views

Adapting third party conversions

I have a couple of pieces of functionality that are similar but not quite the same. They both involve converting a type that I own to other types that are owned by a third party library, so out of my ...
0
votes
1answer
79 views

Where should the domain rules be applied on user input?

The application is an API. Users can post data to the API, which is then transformed to a domain object. I am wondering where to apply the domain rules, in the domain object. Let's make it more ...
8
votes
4answers
1k views

Iterating a class representing a collection: IEnumerable<T> vs custom method

I often find myself needing to implement a class which is an enumeration/collection of something. Consider for this thread the contrived example of IniFileContent which is an enumeration/collection of ...
0
votes
0answers
93 views

MVVM composite ViewModel for sharing fuctionality (instead of inheritance)

I'm looking for design ideas for something like a composite ViewModel. I'm facing a situation where a lot of ViewModels need CRUD operations and some need refresh operations. A minority of ViewModels ...
2
votes
1answer
97 views

Whether to replace mutually exclusive but poorly related properties with an interface

A few years ago I designed a class which had two properties. The two classes ChildA and ChildB had a rich protocol with many properties and methods, but were only distantly related in my model. They ...
0
votes
2answers
616 views

Best way to implement Windows service in C#

I have written a C# service using MVC (No view). The program starts execution and processes some data from database and stores some aggregated data and works just fine in VB whenever i run it. ...
1
vote
0answers
66 views

How to design the Unity Container?

I have three projects: WebAPI, Services and Repository. WebAPI has a reference to Services and Services has reference to Repository. Now I need to add a Unity Container for Services and ...
1
vote
4answers
221 views

How to organize code based on functionality

I use MVC + service classes in my project. My projects structure looks like this: -MySolution.Web -MySolution.Models -MySolution.Services -MySolution.Common MySolution.Web is an asp.net web ...
1
vote
4answers
432 views

IDisposable without finalizer in a Singleton scenario

Is it a right expectation that if a C# class deals with unmanaged resources and implements IDisposable, then it also should implement some kind of finalizer logic? We have a vendor-supplied utility ...
0
votes
0answers
42 views

API design question for a Builder class

I have a couple questions regarding the best way to present a Builder's API. Lets say we have an enum that we'd like a user to set through the builder: public enum PositionType { Anywhere, ...
0
votes
3answers
539 views

C# How to avoid duplicate code with interfaces where objects have the same behaviour

So a simple example i have: public interface IFollow{ Transform Target {get;} void LateUpdate(); } public A : Monobehaviour , IFollow { public Transform Target {get; set;} public void ...
1
vote
1answer
291 views

Wpf Application Structure? C#

I'm trying to port an application of mine from Java to C# and I can't for the life of me wrap my head around Wpf application structure. In Java my application runs the main() method which registers ...
25
votes
2answers
3k views

Implementation of pure abstract classes and interfaces

Although this isn't mandatory in the C++ standard, it seems the way GCC for example, implements parent classes, including pure abstract ones, is by including a pointer to the v-table for that abstract ...
0
votes
1answer
105 views

C# - How should I design my server? [closed]

I'm confused in designing a TCP server with C#. Where should I put my TCP Listener ? inside Program class or create Server class ? or ... Where should I start handling client ? from Listener accept ...
1
vote
1answer
99 views

Entity Framework Entity Names

As an example, I have a POCO called Person which is used in my presentation layer and my business logic layer. I don't want to use this POCO in the Entity framework because I don't want that class ...
3
votes
1answer
350 views

ToList() vs Using default list constructor

After reading rules of Clean Code, one of them is to use default constructor when using transferring data from one collection to other. For example i have : Dictionary<string, string> dict = ...
65
votes
7answers
15k views

If functions have to do null checks before doing the intended behaviour is this bad design?

So I don't know if this is good or bad code design so I thought I better ask. I frequently create methods that do data processing involving classes and I often do a lot of checks in the methods to ...
-3
votes
1answer
663 views

UML Class Diagram HashMap Data Type

How can I show a Java HashMap data type in UML Class Diagram (or C# dictionary)? I.E. This class: public class Test { private Map<String, String> map; private Map<String, int> ...
0
votes
1answer
72 views

How do I abstract the request/response values between UI/Presentation?

I have given the following architecture: Layers: Bootstrapper MyApp.Start IoC-Container etc. UI Layer MyApp.Gui Views ViewModels Business Layer MyApp.Core DataGenerator DataGeneratorRequest ...
3
votes
3answers
1k views

Onion architecture: layer placement of business logic

Where should the business logic for a project that utilizes Onion Architecture be placed? In my case, it's a C#-based project, utilizing Web API and possibly a MVC UI for the presentation. But ...
0
votes
1answer
131 views

Enum as part of domain - enum + extension or consolidate into one class?

I have a program where the domain is focused around programs. As part of the domain, I have a 'ProgramType', which is an enum formed mostly via a string from the database but also via a bit of logic. ...
0
votes
2answers
225 views

Websockets vs ajax call for scheduled event?

Intro I have been weighing the pros and cons of using websockets vs an ajax call for an event which will happen every x number of seconds (in this case 5). I'll start by explaining the scenario. ...
1
vote
0answers
345 views

Where should I put my enums and interfaces?

I have an asp core MVC project for a college and I would like to implement a timetabling feature. To see if I could successfully even generate a dynamic HTML timetable, I started playing around in a ...
2
votes
1answer
144 views

Is it a good idea to release an application with custom performance counters?

I have been reading on C# Performance Counters and I was wondering if I should be keeping them in my release build? I have never encountered an application that has it's own custom performance ...
30
votes
9answers
5k views

Designing a Class to take whole classes as parameters rather than individual properties

Let's say, for example, you have an application with a widely shared class called User. This class exposes all information about the user, their Id, name, levels of access to each module, timezone etc....
1
vote
3answers
289 views

How to handle fails caused by business rules and return reason to end user?

Let's say I have a asp.net-mvc application and I have to check that object can be deleted before deleting it. public class ItemController : Controller { public ActionResult DeleteItem(int itemId) ...
6
votes
1answer
419 views

How long should Websockets maintain connection

I've created a rest generic service which additionally consume a websocket per resource my websocket code looks like so: initialize(hubSubRoute: string): void{ const accessToken = this....
-3
votes
1answer
164 views

Unit Testing with multiple dependencies

Based on this Q: https://stackoverflow.com/questions/50968762/callback-not-being-called I understand (and its obvious in retrospect) what I'm doing wrong. However given the scenario as unit testing ...
1
vote
2answers
73 views

Real Work in Constructor vs Factory Method [duplicate]

So been doing a lot of reading/research into clean code/design, OOAD, refactoring, TDD, etc. Just trying to improve my designs to be easier to extend and maintain. One thing that is come up quite ...
1
vote
6answers
459 views

How can I unit-test the presence of specific file contents, through an interface?

I am currently trying to test a file manager class. This class is responsible for keeping track of how long the file is good for. The file will have a date written into it that denotes when it was ...
1
vote
0answers
82 views

Are constructors with complex initialization logic always bad? [duplicate]

I've recently read this blog post regarding what a constructor should do and I am also reading Eric Evans' book on Domain Driven Design. Both the blog post and the book state that a constructor ...
0
votes
2answers
99 views

Handling a limited resource in rest WEB API 2

I have developed a restful WEB API 2 (C#, .NET 4.7) for an internal integration project. In my API's backend, I need to use a vendor's dll in order to process the provided input. The vendor's dll is ...
-2
votes
1answer
123 views

Avoiding multiple calls to SQL and persist data

I often received messages objects and for each of them I need to query the database in order to achieve some additional information from one database table. Since we are performing many requests to ...
2
votes
3answers
442 views

What does it mean when something is hard-coded like in gaming?

I'm trying to remove some restrictions programmed into a game like Sims 3 but some features like age restriction are hard-coded in the game's code so I read some tutorials and I found out that it's ...