Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
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 ...
user avatar
  • 43.8k
32 votes
Accepted

Autofac DI container in console app

Your Main method has too many responsibilities: it's your application's composition root, and it's executing the program's logic... if printing to ...
user avatar
17 votes

Extensible code to support different HR rules

public class EmployeeLeave : ILeaveRequest ... var leaveRequest = new EmployeeLeaveDetail(); This is confusing. Going by name, ...
user avatar
  • 2,286
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 ...
user avatar
  • 49.9k
13 votes
Accepted

Will this Circuit Breaker catch fire?

Style/Readability Unnecessary XML comments. For example: ...
user avatar
  • 5,714
13 votes
Accepted

ViewModel creator design

I would say your design is fine. In general I advise injecting IHandleViewModel<T> implementations directly into consumers, because this makes it easier to ...
user avatar
  • 371
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, ...
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 ...
user avatar
  • 236
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 ...
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 ...
user avatar
  • 8,498
9 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: ...
user avatar
  • 6,123
8 votes
Accepted

Is this a sensible way of using an IoC container?

No. What you are doing is called The Service Locator Antipattern. And it's a bad thing. The basic rule of thumb: Don't inject the container!. The IoC container is supposed to be some sort of ...
user avatar
8 votes
Accepted

Do I need ninject when implementing DAL with generic repository and unit of work?

Yes, you need a IOC container to maintain your instances. No, your Unit of Work should not create them. With an IOC Container, you centralize the control over the objects and their lifetime. This is ...
user avatar
8 votes

Do I need ninject when implementing DAL with generic repository and unit of work?

Do I need ninject when implementing DAL with generic repository and unit of work? That's not the question. Inversion of control, repository and unit of work are patterns. Ninject is an IoC container -...
user avatar
8 votes

YARPI: Yet Another Repository Pattern Implementation

I think this is pretty much done. You have great naming. No glaring bugs as far as I can tell. It's clear and concise. Very OOP, which is impressive given the language. Even the high level design ...
user avatar
  • 30.7k
8 votes
Accepted

YARPI: Yet Another Repository Pattern Implementation

The NewItem implementation in the CustomerGroupsRepository has something weird going on: ...
user avatar
8 votes
Accepted

Allowing query handlers to use other query handlers

I have decided to let my query handlers use each other, and build upon other query handlers results. Is that considered okay? What issues may I run into in the future (if any)? Is the code SOLID? You ...
user avatar
  • 371
8 votes
Accepted

IoC.Resolve deep in the project or Constructor Injection on entry point of app

"Should I resolve my interfaces in one place? " Yes. This is called a composition root. You should definitely not use your IOC container as a service locator. This is considered an antipattern and ...
user avatar
  • 3,753
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 ...
user avatar
  • 478
7 votes
Accepted

Down the rabbit hole with MVP

There's usually very little I can say about your code, but maybe if I just start going down line by line I'll find something. I'm hoping someone else who knows more about mvp and dependency-injection ...
user avatar
  • 30.7k
7 votes

Unit of work + repository + service layer with dependency injection

public interface IUnitOfWork : IDisposable { IRepository<T> Repository<T>() where T : class; void Commit(); void Rollback(); } The goal of ...
user avatar
7 votes

ViewModel creator design

Why the marker interface? ...
user avatar
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 ...
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 ...
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 ...
user avatar
  • 186
6 votes
Accepted

Should a Factory ever be generated per request?

Just got one thing to say on your code: Your Comments add close to no value! your code is littered with comments and empty lines ...
user avatar
  • 25k
6 votes
Accepted

Refactoring method to make it unit testing friendly

Following on what Magnus said in comments can you not inject the necessary dependencies. For example: ...
user avatar
  • 6,407
6 votes
Accepted

Send message with SignalR to client(s) from injected (IoC) method

Service Locator Alert!! Your SetupHub class has a hardwired dependency on the IoC container itself - this is not dependency injection. When DI is done right, you ...
user avatar
6 votes

Send message with SignalR to client(s) from injected (IoC) method

Currently, your setup doesn't allow for any cancellation or error handling. The latter is an implementation detail, so I guess you've handled that in the actual code. I would consider the following: ...
user avatar
6 votes
Accepted

Unit/integration tests

Regarding your fluent approach to assertions, I'm definitely a fan of anything that makes tests more succinct and readable - as long as it's crystal clear what's going on. A one-liner like "kernel = ...
user avatar
  • 76

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