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
0answers
12 views

Should we put small, potentially often-used pieces of code into tool methods in a shared library?

I recently switched jobs to a new company which develops a .NET framework based product which has been on the market for like 15 years already. Some of the engineers are in this project almost from ...
-1
votes
0answers
10 views

DDD - Should those be Domain Services?

I'm currently developing a system that is being developed under DDD tactical patterns and while implementing the logic on some of the parts of the project I got confused about two things. I have ...
2
votes
2answers
95 views

Calculating method with complex result

i have a method that calculates the price a certain vendor gets for an item. Simplified it checks whether we have a prices for that specific vendor, if not check if we have prices for that specific ...
0
votes
0answers
35 views

Elegant way to prevent global CSS styles from being inherited by views (C#, ASP)

I've been working on a web app that's divided up into different web pages (around 20). It's only used within my company and it looks at financial data. It's a few years old and is in dire need of an ...
0
votes
0answers
23 views

c# Asp Net Core Identity divide the frontend from the backend

I have a question about the architecture of my IdendityProvider for User authentication. For security, I would divide my frontend exposed on the internet from backed that is internal to my network ...
0
votes
1answer
5k views

Extension objects pattern

In this MSDN Magazine article Peter Vogel describes Extension Objects pattern. What is not clear is whether extensions can be later implemented by client code residing in a separate assembly. And if ...
0
votes
0answers
115 views

Designing reusable game/chat server

I'm encountering difficulties with making a reusable design for a game server in C#. Are there better architectural or design patterns that could be used here? If I group similar system functionality,...
6
votes
2answers
14k views

What is the difference between C# and Visual C#?

Let's say I want to start learning C# so that I can program Unity with it. I look for a well-reviewed book and it says: "Learn Visual C#!". I ask myself what the difference between Visual C# and C# is....
0
votes
0answers
58 views

Does Asp.Net Identity worth the overhead?

I'm creating web applications using Asp.Net Core Identity with N-Tier architecture. Lately I've been discovering many properties of this library that I didn't know before as I need to configure the ...
3
votes
3answers
103 views

How to design and join more complex entities

I am developing a small ERP software. I'm wondering how to design entities as well as where to join them. Im just gonna start with an example, that makes it way easier. Say i'm modelling a ...
0
votes
1answer
51 views

Is there still a place for non-async methods in Data Repository?

If we start a .NET Core 3.0 project today, which will use database connection (for example ASP.NET Core Web API), is there still a place for non-async operations while talking to the database? Or in ...
3
votes
3answers
162 views

Should an interface be defined in the infrastructure layer if it's only used by an implementing class in that layer?

Overview If an application is being developed following a clean architecture / DDD approach, my understanding is that the application core or domain layer should contain classes and interfaces that ...
0
votes
3answers
246 views

Designing a class whose dependancies require “starting”/initializing step

I have Facade class which requires an Endpoint instance to function (it uses it in most of the functions). Endpoint is attached to Platform that is passed in Endpoint's constructor and has to be ...
1
vote
3answers
143 views

C# Design question about a specific game combat implementation (with a event system for status effects)

im working on a RPG (combat system) and have a question about a specific part of the design / code. First I have to explain some background information about the system: Every time a character deals ...
2
votes
1answer
108 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 ...
27
votes
8answers
8k views

In C#, is there a way to enforce behavior coupling in interface methods or is the fact that I am trying to do that a design smell?

Many times I want to define an interface with some methods that maintain a behavior relationship between them. However, I feel that many times this relationship is implicit. With that in mind, I ...
1
vote
1answer
72 views

How to avoid circular references with EF Core and Global Query Filters?

We're working on building a multitenant application, and we're using Entity Framework Core as our base data provider. With EF Core, you can use Global Query Filters to define custom filters that apply ...
7
votes
7answers
2k views

Prevent developers from using constants

I have one one software system which allows developers to specify an ID or name to create NodeReferences. Both work fine, but ID's are not guaranteed to be the same across different environments. I've ...
0
votes
1answer
100 views

Storing persistent settings for each product in list

Sorry if I'm not clear, I didn't touch the program for almost two weeks. I have a program that reads XML files: A product list Each product's default settings (if custom is not available) Each ...
17
votes
4answers
24k views

How to best to organize class and interface files?

OK .. after all the discussion I'm changing my question slightly to better reflect a concrete example that I am dealing with. I have two classes ModelOne and ModelTwo, These classes perform ...
1
vote
2answers
105 views

How should a streamwriter be passed to an object considering OO and DI

I have an class named FileCreator which is used to write many strings to a stream. Basically, to achieve its job, the FileCreator needs two objects: a StreamWriter and the actual strings that will be ...
40
votes
3answers
14k views

Why is the logical NOT operator in C-style languages “!” and not “~~”?

For binary operators we have both bitwise and logical operators: & bitwise AND | bitwise OR && logical AND || logical OR NOT (a unary operator) behaves differently though. There is ~ ...
1
vote
1answer
84 views

Result return types in complex transaction

So, I came upon the code similar to the example below. One thing that bothered me about it was the fact that it's dependent on a Result object being created in the Application Service then passed down ...
4
votes
2answers
503 views

Is there anything wrong with writing getter/setter methods in C#? [duplicate]

I am a Java dev for almost all of my programming (at least in the workplace) but I do some Unity for fun on the side. I have used C# properties many times and they are convenient to still provide ...
2
votes
1answer
90 views

Modelling seats of a table in a social game

Assume we want to model a table where players can sit down to get together to play a game (card games, dice games, ...). Assume a few properties associated with each seat class Seat { public int ...
9
votes
2answers
1k views

What is the name for the integer part of a enum?

I've been writing some code comments, and I've been trying to refer to the index integer of a enum type, but I'm not sure what it's called. I'm tempted to call it the identifier, however there is ...
1
vote
2answers
111 views

What is the rationale for naming the code module differently to the class name

For class Foo, what is the rationale for calling the physical code module something different e.g. FooBar.cs Is this just a style thing, or does it serve some other purpose/intent? It is accepted ...
30
votes
5answers
30k views

When and why to use Nested Classes?

Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience. What are nested ...
3
votes
1answer
106 views

How should equality be defined for classes that implement same interface?

Suppose I have two classes that implement the same interface, as in the example in C# below: public interface ICommonInterface { string Text { get; } int Count { get; } } public class ...
0
votes
0answers
29 views

Granular application security in a multitenant application that utilizes a centralized identity server

We are currently rewriting many of our internal desktop applications and converting them over to white-labeled, multi-tenant web applications. As part of the transition, we've setup a centralized ...
0
votes
0answers
26 views

Subscribing to events in factory — better place?

I'm implementing an event-driven game in WPF and have the following Blackjack class: public class Blackjack { public Dealer Dealer { get; } = new Dealer(); public Player Player { get; } = new ...
8
votes
3answers
4k views

what kind of certificate needed for my application ?

I am releasing free C# softwares I've created using Visual Studio. In the future, some of these softwares might become Paid. I was wondering if I need to purchase any kind of license for them ? I ...
2
votes
1answer
116 views

How to properly decouple using interface

I have a ecosystem simulation where animals move and collide with each other. Here is how I handle collisions: public void HandleCollisionBetween(Animal a, Animal b) { if (a.GetType()....
1
vote
1answer
33 views

Designing multi-user system to allow running updates

I am at the beginning of designing a system to be deployed across a job site, your boring, dime-a-dozen, database server backend multi-client system. One feature that I am very keen to implement in ...
3
votes
2answers
380 views

Propagating Data to multiple ViewModels - C#

I'm a bit new to MVVM, but here's my dilemma: I have a model (or models, but let's keep it simple) I want to show that model data on multiple different views. Ok, so ViewModel for each view gets ...
2
votes
3answers
149 views

What options are available to replace an `enum` with a multi-type solution?

A Quick Note I know the question title is a little odd but I haven't had much caffeine this morning so I'm having trouble thinking clearly right now. If you have any suggestions for a better title, ...
1
vote
1answer
39 views

c# xml import and validation with different document versions without XSD

Context: I have a case where I need to extend some existing functionality for loading a new version of an xml file into a system (new fields, some mandatory that were not mandatory before, etc). The ...
1
vote
1answer
104 views

Unit test compiled dll or shared code

I have code in a (Visual Studio) Shared Project, and a number of end solutions/projects which compile and build the Shared Project to various environments (repo). When writing unit tests, I will want ...
0
votes
2answers
150 views

Should I assign a default value for this property in the constructor?

I'm currently creating a class in C# that will be utilized to help standardize calls to restful web services in my company's code. While the majority of my code has been written and well tested, I ...
5
votes
5answers
305 views

How to avoid many objects in constructors when many steps are performed by a class

I have a process which must do 8 steps, in a particular order. One of the step involves sending an email, another one going on a distant FTP server, another one querying a database, and so on. Now to ...
0
votes
2answers
169 views

Entity unique identifier in domain driven design

I'm just learning DDD and a question raised in my mind about unique identifiers in an entity. Consider this simple method that checks the uniqueness of an entity to prevent duplication: private ...
0
votes
1answer
72 views

Using WebAPI as infrastructure layer in ASP.NET MVC

I'm starting a new asp.net mvc core project and for my infrastructure layer I'd like to use WebAPI as this layer should be usable in other solutions besides this one. I'm not really experienced with ...
1
vote
1answer
108 views

What is the Difference between Reactive Extensions and Message Queue?

I am trying to understand the difference between Reactive Extensions and Message Queue? Are they competing frameworks? Can they be used in conjuction? Started programming, and trying to understand ...
1
vote
5answers
237 views

What is best way to handling exceptions without users see errors for technical supports?

Assuming you have a software which you gave to clients. Now we all know that exceptions can be saved to files, databases, and so on for tracing errors by technicians. As all engineers know, no Apps ...
2
votes
2answers
114 views

Different types of account transactions

I'm working on a system where users have different types of 'Accounts' of the financial type. I'm struggling to come up with a design that works. Background A user has 2 types of accounts: A 'tab' ...
0
votes
1answer
37 views

How to design a repository when datasource differs based on DML/READ operations?

We are starting our new application in which we using MS SQL DB for all our insert/update/delete/select ie. both SELECT and DML operations. But, soon we will have two different sources. SQL Server ...
2
votes
2answers
89 views

Where should objects be built from view-models in a layered architecture?

Having the following classes: Person.cs namespace Project.Domain { public class Person { public int Id { get; set; } public string Name { get; set; } public decimal ...
-2
votes
1answer
87 views

How Interfaces Will Help in Real time Scenario? [closed]

I'm working in a real-time project. They are using 3 tier architecture using interfaces but I am not getting how it will work as Dependency injection. I know interfaces can be multiply-inherited and ...
0
votes
1answer
62 views

Throttling notifications from child ViewModel to parent ViewModel

I have a child view-model which notifies on a property change: public class ChildViewModel : INotifyPropertyChanged { private bool isSelected; public bool IsSelected { get => ...
3
votes
2answers
396 views

How to generate a Natural key for a Domain entity?

I was reading this question recently: ID properties on Domain objects in DDD The question talks about having an surrogate key in the infrastructure layer, which is a database ID. I use a Guid for ...