Stack Exchange Network

Stack Exchange network consists of 175 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
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [c#]

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

0
votes
1answer
33 views

Can a query handler (not repository) access a web service?

Say I have the following class, which maps to a database table: public class Person { public Guid Id {get; set; } public string Name {get; set; } public DateTime DateOfBirth {get; set; } public ...
5
votes
1answer
394 views

Clarification about Event Producer in StreamInsight

I need a small clarification about StreamInsight, I know by doc's that StreamInsight can handle multiple concurrent Events. But will the event producer be a separate function, for ex: I need to watch ...
0
votes
0answers
37 views

c# Which design pattern use for this flow [on hold]

I'm writing an application in which each command is a class like ICommand Pattern.In my Login command i have a little bit complex flow,where there are many steps to take and I don't know how to ...
2
votes
3answers
92 views

Web page: randomised collection of paged items retrieved via rest api call

Using .Net web api I have a web page that renders a collection of items depending on filter values applied via an ajax call to an api endpoint. The items are paged so that if the user scrolls to the ...
0
votes
4answers
112 views

How do you manage objects that are shared between back-end services and front-end services/apps?

I have multiple REST-ful APIs that I'm using as my "back-end". I also have multiple web apps (.NET MVC). These web apps make calls to the APIs for data. So, an object being returned by an API will be ...
2
votes
2answers
1k views

Defining a Web Service Endpoint via Configuration instead of Code

I'm interested in creating a web service endpoint in C#/.NET that is fully configurable. To keep it simple assume there is no GET/query/retrieval requirement. I just need some guidance on how to get ...
1
vote
3answers
207 views

Determining response codes from void functions OOP

I am trying to create a Put endpoint using rest. Let's say that under the link /addresses/12345 I am trying to add a new address (if that id doesn't exist) or I'm trying to update it if it does ...
0
votes
2answers
736 views

Best design pattern for two specific scenarios, the first one fits neatly into a Unit of Work(UoW) pattern

I have a question about what the best design pattern to use would be. I have 2 specific scenarios, the first one fits neatly into a Unit of Work(UoW) pattern. The second is a little bit more fiddly. ...
0
votes
2answers
59 views

What is the appropriate architecture to access variable in parent from element of child list?

I have a Parent object which looks like this (pseudocode): class Parent { String token; Child[] children; } It contains a token string and an array of Child objects. My problem is that each of ...
3
votes
3answers
396 views

Is it bad practice to create an interface only to combine two other interfaces?

I'm working on an infrastructure for inter process communication. I have created two interfaces, one to send data and another one to listen to data being sent: public interface ISender<T> : ...
167
votes
5answers
141k views

When do you use a struct instead of a class? [closed]

What are your rules of thumb for when to use structs vs. classes? I'm thinking of the C# definition of those terms but if your language has similar concepts I'd like to hear your opinion as well. I ...
0
votes
0answers
29 views

How to consume nested objects in API resource

I am building my first web application, it links to the serverside through RESTfull Web API (Angular on client side, ASP.Net Core and EF Core on serverside, Automapper to map API Resources to/from ...
1
vote
1answer
79 views

What is the proper way to change the View from a ViewModel when using the MVVM pattern?

I'm trying to follow the Model–View–ViewModel pattern in a Xamarin application and am wondering how the View should be able to change when a given ViewModel is finished. Below I have listed the ideas ...
1
vote
2answers
1k views

Is there a canonical way to handle JSON data format changes?

Problem Say we have a C# class with is serialized to JSON (currently via Newtonsoft's JSON.Net) and stored in a database: public class User { public string authInfo; } If the class definition ...
1
vote
1answer
140 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
4answers
145 views

Are there advantages to testing accessors separately?

If I were to have a class with a property on it should I be testing the get and set functionalities separately or together? class MyObject { public string Name { get; set; } } [TestClass] class ...
0
votes
0answers
39 views

.NET WPF Best way to store a connection credential

I have an application that connects to SQL Server using windows credentials, which works very well for the domain paradigm. The client is now transitioning away from having a domain server, and is ...
0
votes
0answers
20 views

Designing the API of a VMF (Variable Message Format) Parser [on hold]

Variable Message Format (VMF) is covered by the MIL-STD-2045-47001 and MIL-STD-6017. The tl;dr for these standards and the format is, that it represents a message format, which contains variable ...
0
votes
2answers
136 views

How to implement a combination of behaviours for my objects

I need to create a program to manage an association. Members of this association have different roles and each role has specific characteristics. My problem is that I'm not able to abstract this ...
0
votes
2answers
57 views

Approach to handling multiple instances of an application that make large database operations simultaneously

So, essentially the flow of my application works like this: A user selects some options to start a process on the server. Once they hit submit, on the server it opens up a console application that ...
0
votes
1answer
45 views

Updating sub-properties via Entity Framework

I was wondering how to updated nested objects/sub-properties when using Entity Framework. But to make things clear, let's start with an example. I have an object, which can own a number of other ...
12
votes
6answers
6k views

Try/Catch/Log/Rethrow - Is Anti Pattern?

I can see several post where importance of handling exception at central location or at process boundary been emphasized as a good practice rather than littering every code block around try/catch. I ...
6
votes
5answers
346 views

Is there a reason to define an interface for a pure data class?

I am reviewing a colleague's code and as part of the changes, this person introduced a few new pure data classes like so (C#): public class Result : IResult { public bool Succeeded { get; set; } ...
1
vote
2answers
50 views

Branching SQL relationship to C# object model

I'm developing a C# WPF desktop application where I need to read/write to an SQL database regularly. Now I want to map the data from the database to objects in C#. I can't use Entity Framework so I'm ...
2
votes
1answer
91 views

Changing static method that now requires a runtime dependency

I had a simple static method which would take a value and a unit type (pounds, gallons, dollars) and would just format a string. A simplified example: public static string Format(decimal value, ...
2
votes
2answers
106 views

Dependency inversion vs repository pattern (app layer dependency on ORM)

Let's say we have an application layer with some command handler and we use an Entity Framework database context/ORM context in that handler. I would invert dependencies from the Entity Framework/...
0
votes
2answers
125 views

Can I build a fully open source app with .Net Core [closed]

I am thinking about starting an open source project and right now I am deciding what technology stack to use. At the moment, my main coding experience is using C# and I am wondering if I can build a ...
2
votes
2answers
239 views

Factory that returns multiple implementations of the same interface

A few developers and I are attempting to refactor a class that has grown too large. Currently this class is around 3K lines long. The goal of the refactor is to make the logic more maintainable. The ...
0
votes
2answers
115 views

How to avoid ad hoc constructor for unit testing

According to the answer in this post Should my classes have separate constructors just for unit testing? ad hoc constructor is not good and should be avoided. Unfortunately, I have the same problem ...
-2
votes
4answers
98 views

Mocking dbContext vs Repository

I use entity framework with Repository Pattern. while searching for means of writing unit test cases that run isolated from the database I found some people mocking the database context and others ...
5
votes
1answer
237 views

Is it better to use lambda functions or boolean variables to record state

I have heard some people claiming that boolean state variables are generally bad and should be avoided when possible. Apparently in many cases it is possible to put state into lambda functions, ...
0
votes
2answers
125 views

Is using HTTPS for web service calls secure enough?

I'm developing software that calls a SOAP web service I've created. My questions are about security: Is it "enough" (about securing web service) to have my web site secured with HTTPS, and to call ...
0
votes
3answers
154 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 ...
0
votes
4answers
319 views

Is it possible to infer the the generic type from a generic method?

I'm making an HTTP API client class. I want a Perform() method which takes a request object and returns an obejct that is expected from the API. So a PostRequest object will describe how to get a ...
44
votes
1answer
4k views

Which C# practices should be avoided in C++? [closed]

I'm currently teaching myself C++. I'm very proficient at C#, and was wondering which common practices in C# can lead to difficulties in C++, and what a C++ programmer should do instead.
14
votes
6answers
44k views

Understanding the static keyword

I have some experience in developing with Java, Javascript and PHP. I am reading Microsoft Visual C# 2010 Step by Step which I feel it is a very good book on introducing you to the C# language. I ...
3
votes
2answers
155 views

Should AutoMapper be used to Map from ViewModel back into Model?

Should AutoMapper be used to take data from ViewModel and save back into a database model? I know the opposite practice is good software practice: to have Automapper to extract database models, and ...
1
vote
1answer
72 views

Knowledge-based authentication using Domain-driven Design in C#

I previously asked this question on Code Review but was told this was 'off-topic' so I am trying it here. I hope someone can help guide me. As part of an insurance claims system we have created, the ...
5
votes
3answers
316 views

Should I use the Factory Pattern when instantiating objects with very different constructors?

Let's say (just for the sake of example) I have three classes that implement IShape. One is a Square with a constructor of Square(int length). Second is a Triangle with a constructor of Triangle(int ...
10
votes
1answer
7k views

How can I apply the MVC pattern to a C# WinForms application?

I'm a C++ developer who has been using the MVC pattern to design GUIs ever since. Recently I wanted to get back into C#, and I set up a Windows Forms application, but now I am a little bit lost on ...
65
votes
10answers
18k views

What is a proper use of downcasting?

Downcasting means casting from a base class (or interface) to a subclass or leaf class. An example of a downcast might be if you cast from System.Object to some other type. Downcasting is unpopular, ...
3
votes
1answer
112 views

Transforming a long-running operation into a step by step operation?

I am working on a video game in Unity and at some point I'm facing a tough problem to solve: The game freezes while loading level data. Let me lay down what's happening in that process that takes a ...
0
votes
1answer
117 views

Factories to create same objects with different data sources

I have several handlers classes that implements same interface and factories to create handlers. Handlers: public class Handler1 : IHandler { private readonly IService1 _service1; private ...
0
votes
1answer
97 views

Does a 'leaky' repository implementation defeat the point of a repository?

I've seen some tutorials and examples of implementing a repository pattern, and I don't quite understand something. My impression was that the whole point of a repository pattern was to hide the ...
0
votes
4answers
200 views

Do we need Models if we are using ViewModels?

Why do we need Models when we could: Only get the data (which is to be displayed) Populate the ViewModel with this data Pass this ViewModel into the View
0
votes
0answers
27 views

How many exchanges when using scatter gather and CQRS?

I am trying to learn more about CQRS and enterprise integration in my spare time. I have created an application, which uses CQRS and the Scatter Gather Pattern. There are two web APIs for the CQRS ...
1
vote
1answer
272 views

How to avoid Super User account from business?

I have developed a package program 3 tiers architecture. Persistence layer is developed by using Repository Pattern and Entity Framework 6 Code First Approach. This package program has many features ...
1
vote
1answer
107 views

Reducing dependencies between stories & which branch (GIT) should QA's test on?

Background We have a team of 8 devs and 1 QA (tester) and we're struggling with dependencies between tickets and causing a lot of merge headaches and/or people waiting around for the next bit of work ...
5
votes
2answers
700 views

Clean Code: Another question about boolean as function parameters [duplicate]

I had a discussion, if the code for calling information from a database can have a switch to show also deleted entries. Simplyfied the code (C#) look like this: void searchEntry(string searchValue, ...
-2
votes
0answers
72 views

Best Practice on How to Log on the Client (WPF) With a Secret Key

I understand that secrets in the client are not considered secret. But now, I come across a dilemma, how do other client application use logging on the client or how do they communicate with another ...