What is the recommended directory structure of directories in an IoC project

I read several articles and watched many lectures / tutorials on YT about DI and IoC, but I did not find the recommended directory layout in the VS solution.

I am talking about a project (for example, in a game) where you have several classes / interfaces, a registrar, a database provider, wcf services, a wpf presentation level (this is actually a different project) ...

Is there any template project that shows how to organize my project, so that the next experienced programmer will not waste time figuring out what is happening? Just as we talk about β€œcommented code,” I'm talking about a β€œcomment structure with comments.”

For example, should all interfaces be placed in the Interfaces directory? Or should I (in case of registration) create the "Logger" directory and put the interface, classes, class with extension methods (all oriented to logging) there. The code is focused on the Council, in the Council directory. Separate directory for "Field", etc. Etc.

Now the structure looks like this. I'm not sure about Business and Logger. I have an interface in different directories, and then other log classes. Should I call the Log4Net provider? or adapter? or decorator? This is just a log class that implements the ILogger interface. Here is the screen: link

Here is a sample code (there is no IoC yet, but everyone will notice that 3 interfaces will be displayed there. Very simple):

 public class Game { public IBoard Board { get; set; } public Game(IBoard board) { Board = board; } } public interface IBoard {} public class Board : IBoard { public IField[,] Fields { get; set; } public Board(IField field, int boardWidth, int boardHeight) { Fields = new IField[boardHeight, boardWidth]; Fields.Initialize(); } } public interface IField {} public class Field : IField {} public interface ILogger { void Log(LogEntry entry); } 
+5
source share
1 answer

What I usually do is that I have a class MyApplication.Core (Class library), which contains all the application interfaces with minimal third-party dependencies (read: none), for example. ILogger , ICommand or IQuery<TResult> .

Next, I have a class MyApplication.Domain (Class library), which contains all the knowledge about the application domain - this is a business layer. This is an implementation of the main ICommand interfaces, IQuery<TResult> . These implementations then are dependent on, for example, ILogger . Never specific implementations.

Then I have MyApplication.Infrastructure (class library), where all the service interfaces from MyApplication.Core , for example, are implemented. ILogger . Here you may have dependencies on third-party libraries such as Log4Net.

Then I have a presentation layer, which in my case is usually MVC applications, so I would call it MyApplication.Web.Mvc . All controllers have interface dependencies only. Never specific implementations. This level is also responsible for loading all interfaces into specific implementations using Root of Composition .

TL DR:

  • MyApplication.Core (application interface layer)
  • MyApplication.Domain (business logic)
  • MyApplication.Infrastructure (Implementation of the application interface level)
  • MyApplication.Web.Mvc (root layer of the view and composition)
+7
source

All Articles