Skip to content

Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


Follow @CodeOpinion

Query Objects instead of Repositories

The repository pattern is often used to encapsulate simple and sometimes rather complex query logic.   However, it has also been morphed into handling persistence and is often used as another layer of abstraction from your data mapping layer.   This blog post show you how to slim down and simplify your repositories or possibly eliminate them all together by using query objects. A typical repository will look something like this: public interface IProductRepository { void Insert(Product product); void Delete(Product product); IEnumerable<Product> GetById(Guid id); IEnumerable<Product> GetAllActive(); IEnumerable<Product> FindByName(string name); IEnumerable<Product> FindBySku(string name); IEnumerable<Product> Find(string keyword, int limit, int page); IEnumerable<Product> GetRelated(Guid id); } Each… Read More »Query Objects instead of Repositories

Throw Out Your Dependency Injection Container

Dependency injection containers (aka inversion of control containers) seem to be common in most modern applications.  There is no argument against the value dependency injection, but I do have a couple arguments against using a dependency injection container.  Like many other design patterns and practices, over time the development community seems to forget the original problem the pattern or practice was solving. Constructor & Setter Injection Passing your dependencies via the constructor is generally a better way of injecting dependencies instead of  setters. Constructor injection gives you a much clearer definition of what dependencies are needed in order to construct the object into a valid… Read More »Throw Out Your Dependency Injection Container

Simplify Your Code

The rise of package managers like nuget and npm have made taking on external dependencies into your project easier.  Because of this ease, it seems more developers are often adding external dependencies to their project without much thought on the complexity they may be adding.  I suggest you can simplify your code by limiting external dependencies. Frameworks Some frameworks are going to be the foundation to parts of your application.  ASP.NET MVC for example, could be the base framework for your UI.   However, it should not be the foundation of your application.  You should view it as the HTTP interface to your… Read More »Simplify Your Code