Hot answers tagged

31

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 Console can be considered logic. There's not enough meat in this project to even justify using DI/IoC: you have a service that nothing depends on. If you had, say, an Application class: public interface ...


6

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 are letting components be built up by other components. This is completely SOLID and is a good approach. What I would like to warn about is returning ...


6

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 //Create the Container Builder var containerBuilder = new ContainerBuilder(); The comment is in fact almost exactly the same as the code below. And it's not only there, it's the same with every comment in the ...


5

Initial and General Thoughts Good job! Built fine Tests all passed I like the project structure and naming Source control - I find it easier to handle if packages not there, especially on a slow connection Use nuget package restore I generally use this .gitignore file for this type of project https://github.com/github/gitignore/blob/master/VisualStudio....


3

Ef already implements unit of work in itself, as does it the repository pattern. Since you open the connection yourself I take it you use EF6, which also automatically wraps SaveChanges in a transaction if there isn't one already, so you have little use of your UnitOfWork. Read more at Microsoft. If you DO need to open a transaction manually, and you don'...


3

Per my understanding: are you trying to use ContainerStatusGetter as an AggregateRoot? If so, then you need an AggregateRepository that get the IDateTime service from the constructor, and has a GetByOrder([Order Key or Handler]) method that instantiates the Aggregate passing the Service and the Bussiness Model. public interface IDateTime { DateTime Now {...


3

It appears the goal here is to provide parameters to a resolve operation using a different format, something string-based. This appears to be primarily useful in a service location (manually executing Resolve) scenario rather than true DI, so I would caution you to be careful. Since this started as an Autofac solution, I'll post an answer based on Autofac. ...


2

First, I would caution against using the generic repository + unit of work pattern that was super trendy a few years ago because it has problems not unlike the problems you're facing (along with problems stemming from the fact that EF crosses traditional DAL/Domain/BL boundaries). Simply put, I would not use repositories with EF unless absolutely necessary, ...


2

I am not familiar with Autofac (I am a Ninject fan), but I expect similar concepts and implementations, so I have a few ideas: 1) data models serialization I see [DataMember] attributes in your data models, which leads to serialization (WCF?). As far as I know, directly serializing EF data models is not a good idea because it might lead to circular ...


2

Your solution is sane, and it can easily be extended to a generic extension method. Last() is the best you can do. It would have been better if context.ComponentRegistry.Registrations somehow stored some registration meta info like DateTime of registration. There is a meta dictionary foreseen, but it is unclear what is stored inside. public static class ...


1

GitHub and NuGet The right way would be to do not depend on Autofac but support it through AutofacSeriveProvider as many other IoC containers. So now I have this for ioc://: namespace System { public static class ServiceLocator { public static T GetService<T>(this IServiceProvider provider, string uri) => provider....


1

I am going to re-use an old answer. While the context is slightly different, it is basically the same question. UnitTesting with Mocking and Dependency Injection using Ninject As for the other main question: re: lots of constructor arguments. you are right, this is a code smell. a clear indicator of complexity and shows too much of the guts of the internals....


1

I'm not into that whole brevity thing, so I like longer variable names, even for lambda expressions. Plus I like method chaining over query comprehension syntax. I'm weird like that. So the big wiring up block gets a little bigger .. definitely not better, but I wanted to just show an alternative for funsies. builder.Register(context => new ...


1

What are you registering CommandLineTokenizer etc for? this whole code block is equivalent to return new CommandLineExecutor(logger); If all these types are somehow used after all (inside CommandLineExecutor .ctor?), remember that everything created Per LifeTime scope will be disposed at exit out of using and everything created Per Dependency scope will ...


1

You should use virtual keyword if you want to lazy load data. [DataMember] public virtual ICollection<Letter> Letters {get; set;} For IRepository<T>, I would suggest changing List<T> Get(); to IList<T> Get() or IEnumeratble<T> depends on your needs. In the abstract class EFRepository, you could create a variable _dbSetso ...


1

The factory object is pretty easy. You just need a little class reflection: public class RepositoryFactory { public RepositoryFactory() { context = new ApplicationDbContext(); } private ApplicationDbContext context; public object Create<T>() { Type repositoryType = typeof(T); ConstructorInfo ...


1

public class BaseController : Controller { protected IUnitOfWorkService UnitOfWorkService; private readonly IEmployeeService _employeeService; protected BaseController(IUnitOfWorkService unitOfWorkService) { UnitOfWorkService = unitOfWorkService; _employeeService = unitOfWorkService.EmployeeService; } } public class ...


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