43 votes
Accepted

Extensible code to support different HR rules

I coded keeping SOLID principle in mind and here is my code. What did I miss? Let's see... SRP - Single Responsibility Principle A class should have only one reason to change. Violated. The name ...
t3chb0t's user avatar
  • 44.2k
17 votes

Extensible code to support different HR rules

public class EmployeeLeave : ILeaveRequest ... var leaveRequest = new EmployeeLeaveDetail(); This is confusing. Going by name, ...
404's user avatar
  • 2,306
14 votes

Extensible code to support different HR rules

catch (Exception) { throw; } Well this won't buy you anything but a few more lines of code. Just remove the try..catch ...
Heslacher's user avatar
  • 50.4k
12 votes

Finding the lowest and highest values in an array... with "Poor Man's DI"

First of all, kudos for exercising OOP and DI! Coding against interfaces is going to make your life easier in so many wonderful ways! I agree, no problem is too simple to solve with SOLID principles, ...
Mathieu Guindon's user avatar
12 votes
Accepted

Using IServiceScopeFactory without implementing the Service Locator Pattern

I'm of the opinion that this is awesome, and I have a couple of suggestions to add. It's not "Service Locator" because you're explicitly constraining to the exact type that can be resolved---the ...
Granger's user avatar
  • 236
11 votes
Accepted

Stopwatch dependency for unit-testing

I would not return IStopwatch from Start/Stop/etc. This IStopwatch is not an immutable Value Object, like String for example: it would be easier to set expectations by having just this: ...
Dmitry Nogin's user avatar
  • 6,131
9 votes

Extensible code to support different HR rules

A lot of useful comments is here but no-one has commented about the usage of DateTime. EmployeeLeave ...
Paweł Łukasik's user avatar
9 votes
Accepted

Making a web service call based on a type of request

It would be better to give the Irequest interface an additional "Name" property that returns the value of requestType. Than you ...
JanDotNet's user avatar
  • 8,538
8 votes

Extensible code to support different HR rules

Generally speaking, unit tests should follow the "Arrange, Act, Assert"-pattern. Yours only have the "Arrange, Act"-part. You're not asserting anything (with the exception of the one where you're ...
germi's user avatar
  • 488
7 votes
Accepted

UnitTesting with Mocking and Dependency Injection using Ninject

Here be dragons :P This is a conceptual minefield. I have done this exact thing and can relate, you instinctively want to test a lifecycle. a start-to-finish stub implementation..... but don't. the ...
apieceoffruit's user avatar
7 votes
Accepted

Using events together with interfaces in VBA

I use an additional 'event' class, where all necessary events will be placed in, and which will be injected into the interface implementing classes. That. That is how it's done. It's COM-friendly, it ...
Mathieu Guindon's user avatar
7 votes
Accepted

Adding extension methods to IServiceCollection in ASP.NET Core

Instead of doing services.AddThemes(options => { options = Configuration.GetSection("Themes").Get<ThemesOptions>(); }); you could use ...
saluce's user avatar
  • 186
6 votes

Finding the lowest and highest values in an array... with "Poor Man's DI"

Additional to @Mat's Mugs great and detailed answer addressing DI, I would just adding few words about alternative solutions. Because you would like to practice DI, your implementation is absolute OK!...
JanDotNet's user avatar
  • 8,538
6 votes

Making a web service call based on a type of request

As pointed out, you still need to have some sort of if/else, switch, map, etc to decide which class to create for the given requestType. However this doesn't need ...
404's user avatar
  • 2,306
6 votes
Accepted

Full integration test for a Console application

var mainLogger = LoggerFactory.CreateLogger(nameof(Program)); LogEntry.New().Debug().Message("Logging initialized.").Log(mainLogger); This should really be split ...
RubberDuck's user avatar
  • 30.8k
6 votes

Different implementation of an Interface along with additional parameters

Since I am using DI to instantiate classes I have to disappoint you... there is no DI in your code. The only service you are using is instantiated inside the class using it: ...
t3chb0t's user avatar
  • 44.2k
6 votes
Accepted

Socket server in c#

configuration is usually accessed statically I have a different impression. Configuration is accessed in a way that is convenient in terms of maintainability and testing. And static references do not ...
Nikita B's user avatar
  • 13k
5 votes

Dependency problem in C#, through polymorphism, and appropriate design pattern

I want to keep my model without any depdency When one class uses another, that's dependency. OO programming is all about dependencies - we do not (should not) make single monolithic, do-all classes. ...
radarbob's user avatar
  • 7,504
5 votes

Dependency Inversion Principle and Dependency Injection in C#

Adding to @Carlos' Alejo answer there is one more idicator that tells you whether you are on the SOLID side of the force :-] If you tried to add another sex to your first model you couldn't do it ...
t3chb0t's user avatar
  • 44.2k
5 votes

Dependency Inversion Principle and Dependency Injection in C#

The new code seems OK to me. One way to know if you're on the right way is trying to unit test your code. In the old code you couldn't unit test the higher class, as you needed to create real ...
Charlie's user avatar
  • 181
5 votes

UnitOfWork for sending mail

I don't know if this falls under "don't do it", but you shouldn't be passing your "container" around. That should be used to wire things up on startup. The rest of your classes should know nothing ...
404's user avatar
  • 2,306
5 votes
Accepted

Activator with simple dependency injection

You are putting pretty strong limitations on classes you can activate this way - a single .ctor, no default .ctor(which can make serialization troubles later) and all .ctor arguments should have ...
archnae's user avatar
  • 256
5 votes

Using IServiceScopeFactory without implementing the Service Locator Pattern

At first, I liked your approach quite a bit. However, I think there's a smell here that's being ignored. In limiting the IServiceScopeFactory<T>/...
casperOne's user avatar
  • 151
5 votes
Accepted

The Last Lost Bubble Shooter - a Board game for children

...
Pimgd's user avatar
  • 22.3k
5 votes

C# Cryptography Interface

People usually pay not much attention to that, but redundant *Manager, *Processor, *Service ...
Dmitry Nogin's user avatar
  • 6,131
5 votes
Accepted

OOP Dependency inversion principle VBA

An observation on your class constructors. At the moment you are using public properties to allow you to set the value of properties of a class after it has been created. You can take this to the ...
Freeflow's user avatar
  • 645
5 votes
Accepted

Dependency Injected StackExchange.Redis Client

I can share with you an example version of Redis service such as getting subscribers or accessing the other databases and also for catching connection issues. ...
Mustafa Salih ASLIM's user avatar
4 votes
Accepted

Use of Ninject as an IoC container in a WinForms MVC application

This feels a bit awkward: ...
Mathieu Guindon's user avatar
4 votes

Wrapping a .NET Database Connection

I see a few issues with your class: Issue 1 This property is open so anyone can set it: public SqlConnection sqlconn { get; set; } You probably want to make ...
CodingYoshi's user avatar
4 votes

Using dapper Unit of Work in 3-tier architecture

You're correct in point #1 that passing the connection string to each service to get your UoW instance is bad form. I'm not sure if that code was designed for a DI first world as is the case Asp.Net ...
Andrew's user avatar
  • 81

Only top scored, non community-wiki answers of a minimum length are eligible