Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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 votes
1 answer
51 views

How to handle third-party libraries that can potentially throw, without knowing what kind of exceptions they may have?

I'm starting to run into this sort of dilemma while many third-party APIs, but I will use MongoDB for my examples. Consider the following code: var settings = MongoClientSettings....
user avatar
  • 3,839
0 votes
0 answers
26 views

Best way to implement a custom session pool in c# (winscp)

I'm currently implementing a session pool for WinScp sessions, which intended purpose is to open multiple sftp sessions concurrently. While my current solution works, I'm not sure if the solution is ...
user avatar
0 votes
2 answers
128 views

Would Injecting dependencies in C# as default parameters be a bad practice?

Given the (old) debate over whether Singletons are overused/abused/are worth it - would it be a bad idea to inject the dependencies as default parameters? In this way, we could get rid of defining ...
user avatar
  • 295
-3 votes
1 answer
69 views

Using two different languages where one would suffice for the task (microservices)

I previously asked this on StackOverflow, but doesn't fit there and I was suggested to move it here. I was thinking about using two seperate backend languages for seperating concerns in a project of ...
user avatar
  • 97
11 votes
4 answers
2k views

Should we abandon the "if not null" pattern?

I've seen that with the Dictionary API now has methods with bool TryGetValue<TKey, TValue>(TKey key, out TValue value) and I like this kind of methods because they're signaling to the other devs ...
user avatar
  • 350
1 vote
2 answers
66 views

Calculate operation time and setuptime or costprice based on a variable set of parameters - Design Pattern?

I work in a production company where my colleagues calculate costprices based on 3D models and their respective operations. Apart from workactivities where a user has to insert an operation time and ...
user avatar
0 votes
0 answers
23 views

Implementing the Repository/UnitOfWork pattern using Azure.Data.Tables "TableClient"

I currently have a generic Azure repository AzureRepository<TEntity> store internally a list of table transaction actions like so. private readonly IList<TableTransactionAction> ...
user avatar
  • 183
-1 votes
1 answer
83 views

State machine using SOLID principles. Connecting to real devices

I am trying to implement code for switching states of a couple laboratory devices. My considerations are: how should I link the state objects, state machine object and device manager object to follow ...
user avatar
  • 1
0 votes
1 answer
73 views

Blazor Application separation of concerns

I am building a cross-platform application and have planned to use Blazor. I have made similar applications in the past but using ASP.Net Core for the back-end and Angular for the front-end. I always ...
user avatar
0 votes
1 answer
114 views

How to implement automatic SemVer from code changes [closed]

Goal I'm working on libraries published as nuget packages and I would like the version of those packages to update automatically based on the changes I make. In other words, I would like something ...
user avatar
  • 204
0 votes
0 answers
71 views

Doubts designing an old system using DDD

We have the following system: References that identify a product and have a family which identifies a group in which the reference belongs. Families that are a way to group references, for example, if ...
user avatar
  • 33
0 votes
0 answers
25 views

Custom templated controls, user control and MVVM approach

I am developing a data visualisation tool, with some UI interactivity after initial trail with doing it mostly by using templates in XAML and code behind to handle interactive stuff I've realised that ...
user avatar
0 votes
2 answers
142 views

Are there any named principles, best practices, etc, that are being violated here? [closed]

I've come across some code like below a couple of points come to mind and unfortunately I'm having trouble finding any actual named principles or anti-patterns or anything that's been violated here, ...
user avatar
-2 votes
1 answer
125 views

How Should I Go About Refactoring My Code With Dependency Injection? [closed]

I work on WPF applications used in testing hardware. I need to make my code base more testable and re-usable. I believe DI would help, but I'm not quite sure where to start. I've done my best with the ...
user avatar
0 votes
0 answers
37 views

WPF Best way to create viewmodel from another viewmodel

Often I want to open a new window from within some view. I see opening a window as view logic. So I don't want code in my viewmodel that creates/opens/changes windows or anything else that interacts ...
user avatar
-3 votes
0 answers
57 views

How to refactor legacy c# code without unit tests? [duplicate]

Recentely I'm working on an legacy project that Has not any unit tests. Used Entity Framework as data access technology The DbCobtext used directly in the business codes The Project is big(writing ...
user avatar
  • 135
5 votes
6 answers
413 views

Unsupported concurrent calls, throw exception or log a warning?

Context Let's say I have a navigation service that allows me to navigate to a page. The Navigate method is async because an animation (about 250ms) is involved. public interface INavigator { ...
user avatar
  • 204
1 vote
1 answer
77 views

Contextual Implementation Overhead vs Redundancy

I have an application that has use cases relative to where it is used. A local client and server, where all the server data is in a single location and the client queries that server knowing it is ...
user avatar
0 votes
1 answer
131 views

How to handle duplicate validation logic with CQRS pattern

I am implementing a CQRS pattern in ASP.NET Core with MediatR, and I am wondering what the general consensus is for handling duplicate validation logic for queries/commands which operate on the same ...
user avatar
0 votes
2 answers
138 views

How to handle continual method addition to an existing class

I find myself often adding more and more methods to a specific class, is this class heading in an unmaintainable direction? Or is this class fine even if it has 50 or more methods? let's call the ...
user avatar
  • 111
0 votes
2 answers
203 views

Which strategy to use to create object instances

I have this use case (I've simplified it): Each student can apply for one or multiple activities. As of now we only have Swimming activity onboarded on the system, but we expect to have more. Base ...
user avatar
  • 109
3 votes
4 answers
198 views

How to get an ILogger instance from extension methods?

Let's say I have this service abstraction exposed from a library. public interface INavigator { ImmutableList<IPageViewModel> Entries { get; } void NavigateForward(IPageViewModel page); ...
user avatar
  • 204
0 votes
1 answer
118 views

Architecture solution for scalable crawling

I have the following requirements: a list of queries (rather long list ~ 100K - 1M items or even more) that I need to perform in a certain period of time and the execution time must be predictable. ...
user avatar
0 votes
2 answers
95 views

Where should helper classes/methods for transforming business data for the View be located

I have inherited a badly architected and organised ASP.NET MVC application, which is an online booking system for healthcare providers. It seems to have been designed with very few object oriented ...
user avatar
1 vote
3 answers
367 views

Why would you have a different namespace for each folder in a C# project?

I can't see how having a namespace for each folder makes sense. As near as I can tell, the point of having namespaces is to avoid name conflicts. But, Microsoft, in their namespace naming conventions, ...
user avatar
-1 votes
2 answers
145 views

Loop pattern for batch data processing

When processing data sets in batches I usually can think of the following three implementations. Which one do you consider better than the other and why? Notes: The implementation is in C# but the ...
user avatar
0 votes
1 answer
46 views

Better design for a REST import into web store

I have an import that needs to grab data from a REST service and import into an web store. It's basically an ETL type of service, but because the REST service can be slow and I don't want to call it ...
user avatar
0 votes
1 answer
58 views

Mapping destination object from multiple source objects vs constructing using multiple source objects (as in constructor)

Lets say we have DTO class with 15 properties. Usually DTOs like these are mapped from other objects. But sometimes some DTOs may use values from multiple objects. In these cases, should we “Map” or “...
user avatar
5 votes
4 answers
182 views

How to provide logging to consumers of a NuGet package/library

I've been building a library (NuGet package as I'm in the C# world here) & I want to add logging so the consumer of the library can optionally provide some logger to the library. However, there ...
user avatar
-2 votes
3 answers
296 views

Are interfaces made useless by the template pattern?

Refer to the highest upvoted answer here for why you should make an IPizza interface with a IPizza.Prepare() method. This is highly upvoted, But I think the answer is flawed. Sure a pizza can be ...
user avatar
  • 113
1 vote
0 answers
134 views

What design pattern does this implementation follow?

For a middleware solution I expose an API, which processes data and sends the necessary information to different parties. In the current design we create a new client, which acts sort of like an ...
user avatar
-3 votes
2 answers
92 views

Case Statements for string to string mapping [duplicate]

I have a class called SomethingProvider that contains: private static string convertMapA(string convertA) { switch (convertA?.ToUpper()) { case "NONE": ...
user avatar
  • 105
-3 votes
3 answers
310 views

Can be logic around `List<T>.Enumerator._version` considered control flow exploitation?

List<T>.Enumerator “snapshots” list version upon creation by _version = list._version;. This allows enumerator to halt enumeration when List<T> changed during it. This behavior likely ...
user avatar
  • 268
0 votes
3 answers
179 views

Should I send the current or previous state with my state changed event?

I have an event that is raised when my job objects change state (e.g. initializing, running, complete, etc). The event is to be invoked from my set method in the State property, but before I make it ...
user avatar
0 votes
3 answers
143 views

Should I perform simple validation (not null, max length, etc.) in a web api controller and duplicate in a command handler?

I have a question about DDD. I wonder if I should add validation in a web api controller and duplicate it in a command handler? Is it good approach to validate a DTO and a command even if the ...
user avatar
2 votes
3 answers
151 views

Use abstract factory (or an alternative way) to produce an instance of a subclass?

Context for this question I'm currently working with small data storage media (e.g. RFID tags) that contain some fixed number of bytes that can be manipulated. The drivers that allow reading bytes ...
user avatar
1 vote
1 answer
116 views

Builder design pattern when creating object between many layers

I stumbled on following problem, and I'm curious if it could be done better. A while ago I wrote a factory class that looked something like this: public class Foo { private IDbContext ...
user avatar
3 votes
1 answer
150 views

Posts and Comments - how should I define them in domain driven design?

I am designing a blog in domain driven design. I don't know how I should define models: Post and Comment. My database: A user can see a post and related comments. So I think that Post model can be ...
user avatar
-1 votes
1 answer
107 views

Two layers of DTO's for API's with Entity Framework

I am building an API which, amongst other things, needs to handle users. I am building it with C# 10 and .NET 6. In order to receive/return data in the API end points, I am using records. So for ...
user avatar
0 votes
4 answers
145 views

Adapter or pure interfaces?

I got a bit strange 'future ready' scenario. And I'm not sure if I got it right in regards to C# adapter design pattern. The scenario is that to be future ready, 'to use the adapter pattern' to easily ...
user avatar
  • 137
1 vote
2 answers
158 views

Should domain layer have validation logic? [duplicate]

Let's say I have a User class described as follows: record User ( Guid Id, string Username, string Password ) { /* some methods */ }; Let's say Usernames and Passwords need at the very least ...
user avatar
0 votes
2 answers
154 views

How to split logging into streams?

I am looking for an advice (or an example) on how to organize logging streams in my cloud app (C#). In my app there are logging events related to the application infrastructure level and I want to ...
user avatar
4 votes
2 answers
2k views

What does "set" mean in programming languages like C#?

I've been reading a book about C#. What does the word 'set' mean in the following excerpt? Pattern matching with the switch statement: Like the if statement, the switch statement supports pattern ...
user avatar
  • 75
1 vote
0 answers
96 views

ASP .NET Core 6 - .razor components - Routing

I come from a background in ASP.NET MVC 5 on .NET 4.8. I've been trying to wrap my head around the new razor pages, and can't seem to get routing to work, or understand it, even. I don't want to use ...
user avatar
0 votes
2 answers
104 views

Make date range generator interface stateful or stateless?

An app has a feature that's much like any calendar application (like the Outlook calendar for example). Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods ...
user avatar
1 vote
1 answer
144 views

How to test around a giant static class?

I am dealing with an old .net code base which has a PrivilegeChecker static class with hundreds of static methods, each of which takes in some user id and some other params, and then fetches some info ...
user avatar
  • 196
0 votes
1 answer
151 views

How did you work around covariant return types? Before the language allowed it?

I need some help with design logic, illustrated by an example. My question below. public class ChangeSet { } public class NodeChangeSet : ChangeSet { } public abstract class Base { protected ...
user avatar
  • 113
2 votes
3 answers
255 views

Should you use interfaces or classes in database entities?

Let's say I'm making a library database with books and authors, and I want to model the domain with interfaces, should I also specify the relations in the interfaces? For example, if I have the ...
user avatar
-2 votes
1 answer
114 views

What is the right approach for dynamically creation of SQL-queries?

The problem: I have a application where the data comes from SQL tables. The design of the tables differs a bit from client to client. Example: ClientA sells thermometers and the product has features ...
user avatar
1 vote
1 answer
177 views

Circular references with generic classes

I'm trying to create an interaction system for a game I'm developing with Unity and C# and I've been struggling with it for a while now. It consists of interactors and interactables. The idea is that ...
user avatar

1
2 3 4 5
96