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

Consumir un Web Service en C#

I need to consume a web service in C #, but I can not add the reference from the visual studies, and for general the proxy class I can not use the console of the visual commands, everything must be ...
0
votes
3answers
78 views

Domain Models with complex properties construction

According to this article: Using Ids in Domain Models is not a good practice. We should reference the entire domain model instead. In this case, when we want to provide only Getters for our ...
1
vote
2answers
94 views

Best practice when creating classes that are solely in charge of the creation of other objects i.e. factories?

I often find myself creating classes that I suffix with 'Factory'. These classes tend to be solely in charge of the creation of a specific class or set of related classes. However I've always felt ...
2
votes
3answers
160 views

Dealing with API errors

I'm building a shop system which works in three parts: a mobile app (Android/iOS) which is used by customers to make orders, view products and so on, a desktop application, used by the managers to ...
0
votes
0answers
36 views

Synchronization data between API (server) and local database : C#

I hit an API which gives a list of chairs with their location. I save this data in my local database. Whenever I received updated data like add a new chair, update location of the chairs and delete a ...
0
votes
1answer
97 views

Where to store calculated values of an entity

Trying to figure out the best place to store calculated properties related to a base entity class for use through out the application, namely in view models and DTOs. For example, a base entity class ...
2
votes
1answer
1k views

Best practice for transaction handling using Entity Framework

I am developing an app which uses Entity Framework for data access. The architecture of the app somewhat like below: As depicted in the drawing, the business service can be consumed from either web ...
0
votes
0answers
5 views

WPF MVVM validate property before setting when user's change value in DataGrid [migrated]

Issue: I have a list of a class that's being displayed in a Datagrid, one of the values needs to ask the user if they really want to change it. This was implemented with a YesNo MessageBox in the ...
0
votes
2answers
97 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 ...
0
votes
0answers
133 views

Should I check for nulls, even though I won't get any, as far as I know? [duplicate]

I'm new to software engineering and right now I'm focused on learning the best practices to consistently write robust code. Recently I've been maintaining an application built by other people and/or ...
3
votes
3answers
152 views

Is this a good method of separation?

I am creating a web application that is tiered in the following way: Controller > Service > Repository I have a ProductsController which has the following action: [ValidateModel] [HttpPost] public ...
101
votes
14answers
12k views

At what point is brevity no longer a virtue?

A recent bug fix required me to go over code written by other team members, where I found this (it's C#): return (decimal)CostIn > 0 && CostOut > 0 ? (((decimal)CostOut - (decimal)...
-3
votes
0answers
44 views

Are my UML's understandable and do they follow the UML conventions? [closed]

I'm new to software modeling and was hoping someone could walk me through mistakes I've made. I'm trying to show how my parser for our game is working. Said in words, the parser is supposed to take ...
0
votes
2answers
53 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
2answers
54 views

When no other class ever needs to touch the (nested) class - should I always make it a (private) nested class?

And what is the recommended file structure? The question is a bit similar to this one, but I'm looking for more explicit recommendations. In theory I think it's a good concept to keep files short ...
1
vote
1answer
131 views

Force instance methods to use only public members

What do you think about code like this: public class ThisClass { // this method uses only public members public void DoSomething() { AccessToPublicMembersOfThisClass.DoSomething(...
7
votes
1answer
239 views

Is the C# async/Task construct equivalent to Java's Executor/Future?

I'm a long time Java developer, but with so little traffic on SE, I don't limit my viewing to any single tags. I've noticed that C# questions with async/await come up a lot, and as far as I've read it'...
2
votes
1answer
169 views

Must we define methods and async when we don't know whether the implementation is synchronous or asynchronous?

I think I know the answer to this, but it's particular enough that I don't want to go telling other people stuff until I'm 100% certain. Suppose I have a class with some dependency: public interface ...
23
votes
5answers
25k 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 ...
1
vote
2answers
705 views

Making localization files easy to use for translators

I want to make my application available in many languages. I started using Resource Files, but there is a little problem with them. I want other people to have access to these files. Visual Studio ...
0
votes
1answer
945 views

Catching exceptions in service layer without hiding bugs

Let's imagine we have a service CustomerService: public class CustomerService { public Customer GetCustomer(string customerName) { if(string.IsNullOrWhiteSpace(customerName)) ...
0
votes
1answer
70 views

How to manage user serial keys for an application

I have an application in C# where several users access it. Each user will have a serial key associated with his username in a table users in a local MySQL database. Example of the table users: User ...
4
votes
1answer
130 views

Architecture to lock account to mobile device

I'm currently creating a mobile app and have the following issue. I am required to only allow the user to login from a device that is registered to the users account. A user can have up to X number of ...
41
votes
4answers
42k views

Why do C# developers newline opening brackets? [closed]

I've spent most of the last several years working mainly with C# and SQL. Every programmer I've worked with over that time was in the habit of placing the opening brace of a function or control flow ...
4
votes
7answers
8k views

Which is better: many class definitions in the same file or every class definition in a separate file?

Which is better: many class definitions in same file or every class definition in separate file? Examples: 1) Many classes in same file. Say, myManyClasses.cs: namespace myPack { class myClass1(...
6
votes
3answers
1k views

Is it poor practice to have a class implement an abstract class without adding any new fields/members/functionality?

I am writing a wrapper for a REST API and I have run into something I have never had to ask myself before. This API is for E-Commerce transactions, it has SALE and RETURN endpoints (and some other ...
-1
votes
3answers
346 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....
3
votes
1answer
174 views

Using Active Directory ObjectSid as Primary Key in SQL Server for Data Access via ASP.NET MVC

I am designing an Intranet employee reward web app using ASP.NET MVC C#/MS SQL Server. This will only be accessed from within the network. Employees and managers will be able to give a reward to ...
0
votes
1answer
84 views

How can I use disparate concrete classes that share similar functionality to create an interface that abstracts those similarities?

I've run into this issue a few times. I have preexisting framework objects that do not share a common ancestor. An example of this would be a class representing a an environment variable and a class ...
6
votes
6answers
510 views

I need help solving a common architectural problem with multiple concrete classes implementing an interface

I have a common issue I encounter which I've solved with a Factory class in the past but it always felt a little "off". Let's say I have multiple Exporter classes which implement IExporter, which has ...
3
votes
2answers
320 views

Should one make the database calls in the constructor or method of a class?

Take the following instance for example: CreditCardApplication class public class CreditCardApplication { public int Id { get; set; } public string FirstName { get; set; } ...
1
vote
1answer
66 views

Would I have one domain model (.NET Project) for all consumers or one domain model (.NET Project) per consumer?

Say I have a bounded context called: 'Loans' and the following APIs: HSBC NatWest TSB The three banks above are consumers and have an API. I am using the scatter gather pattern (https://www....
0
votes
1answer
27 views

Venue Reservation System Logic Approach/Clarification

I hope this is the right place to ask since this is a programming related question. I’m developing a venue reservation app (similar to booking.com) and am almost done however I have 1 request for ...
1
vote
1answer
347 views

How can I get rid of this antipattern

I have a main window and I amgetting data from http client service while form load. public class MainWindow: Window { private IClientService service; public MainWindow(IClientService ...
0
votes
1answer
201 views

Enterprise Mashups. A good approach for .net

I'm in the middle of trying to talk our management into letting us do a portal that sits across the many, many systems that we use. I believe in using the best tool for the job so we have a good ERP, ...
0
votes
2answers
163 views

Best way to match timezone with time offset?

I have a c# solution which uses mssql database to store data. In my database there is a big table of entities (e.g. accounts) for each of which the TimezoneId field is defined. This field is filled ...
22
votes
8answers
5k views

When is primitive obsession not a code smell?

I have read plenty of articles recently that describe primitive obsession as a code smell. There are two benefits of avoiding primitive obsession: It makes the domain model more explicit. For ...
3
votes
5answers
293 views

Should I add additional unit tests for this helper method that simply aids in refactoring of code?

I have a method: public static void AddPersonToPeopleList(List<PersonModel> people, PersonModel person) { CheckWhiteSpace(person.FirstName, "FirstName"); ...
1
vote
4answers
219 views

C# How to correctly work with ProgressBar? Architecture look

I am wondering about the correct architecture to work with a progress bar in C#. But maybe it applies not only to C#, because I need an architectural look at this. I'll explain my question with an ...
2
votes
1answer
140 views

Design pattern for an indeterminate number and format of questions [closed]

In my application, I have a finite number of question types, but the order in which they're asked and whether they're asked at all is not known up-front. An example analogy is a hotel booking process,...
0
votes
0answers
8 views

Attempted “__set__” operation on ASN.1 schema object [migrated]

I'm currently using IronPython to execute Python code in my .NET project. The issue, however, is that I am receiving an error: Attempted "__set__" operation on ASN.1 schema object This is the C# ...
4
votes
2answers
2k views

why exposing service instead of repository in onion architecture

I'm digging on how to structure projects and so I stumble into Onion Architecture. As to how I understand it, its more on a domain-centered-focus architecture instead of a database-driven type. I'm ...
0
votes
2answers
160 views

What HTTP action and return value should be used on resource's action

I have a question about how I should implement a new action for a resource on my API layer. I have a Timesheet which is used by people to let us know how many hours they worked on a job. This ...
4
votes
4answers
1k 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
81 views

Appropriate pattern for injector that sets a property and client that ONLY gets a property

Suppose I have a method in client code that expects an interface... void DoWork(IDataManager data) { //use IDataManager interface in the DoWork method } And the IDataManager interface looks like ...
2
votes
4answers
386 views

Why does C# not have automatic dispatchers

Why does C# make you put in a dispatcher for a different thread to update the UI? Example: Dispatcher.Invoke(() = { lblerrorName.Content = ""; }); It always gives the 'running on different ...
2
votes
1answer
280 views

Two-level concepts

I find myself lately implementing the same concept twice, once at a low level and once at a higher level. Let me see if I can explain it... For example, given the notion of a database, I have one ...
0
votes
0answers
17 views

Event Sourcing & Redis

I'm using StackExchange.Redis library, it seems perfect. Hard-coded events related BankAccount with ID 1: // UNSORTED COLLECTION public static List<Event> DomainEvents = new List<Event>()...
0
votes
0answers
32 views

MVP pattern in Windows Forms: how to properly open one form from another

I implement MVP pattern in my windows forms application. As you know there is 1:1 means there is one presenter for one view. So basically we can have: public class MainPresenter { IMainView ...
0
votes
0answers
31 views

Is Unity Container Property Injection following Bridge Design?

I have following code written on top of Microsoft Unity. This is the implementation of property injection. I recently gone through a Bridge Design Pattern that separates abstraction from ...