Using IoC containers while waiting for application extensibility

I know there is a similar question here. But I think mine expands this a bit more.

I recently worked on an Application that has been in production for about a year, without any problems and no real expansion plan. The application has several dependencies and uses DI, but without a container.

Now I am distributing the application to a much wider scope in the company's instructions, this led me to implement the use of the IoC container. The problem here was the overhead of adding a container to the code, which, as I thought earlier, would never be needed.

My specific question is when I move forward:

  • When planning and coding small applications, which, apparently, will not expand much, I have to implement the container in the expectation that scenarios like these can appear on my own and in that expectation I would better implement the container from the very beginning, therefore when expanding the framework already exist.

  • Is this a sign of poor design if the implementation of the container when expanding the application beyond its original intent becomes cumbersome?

EDIT:

I use reliable principles (as far as possible) and am currently interacting intensively with my applications, this issue is more about using the IoC container, not the DI itself. The previously mentioned application is its own DI style, which I add to the container in which the question arises.

+4
4

Clean Code YAGNI. " ". DI , . DI , , . - . .

, . . . , , , , , .

, "" , 75% , . , , , , , ​​ . . , . , , , . , , . .

, , . , , . .

+3
  • , DI benificial , ( ). , , , ( stabler)

  • , , . , , DI DIY-. , , , DI.

. , . , .

+2

1. When planning and coding smaller applications that presumably will not expand much, should I implement a container in anticipation that scenarios such as these may present themselves and in such anticipation I would be better off implementing a container from the start so upon extension the framework already exists.

? , , .

2. Is it a sign of poor design if implementing a container when extending an application beyond its original intention becomes cumbersome?

, , . , , , . ? ? , .

, , , .

+1

:

1)

, , . , . , , .

public class MyClass
{
 IUnityContainer _container;
 public MyClass(IMyDependentInterface dpenedentclass, IUnityContainer container)
 {
 _container = container;
 //........
 }

 public void DoSomething()
 {
  var obj = _container.Resolve<ISomeOtherInterface>();
  obj.DoAction();    
 }    
}

-, ( ?). , . , , .

2)

, - . , , , .

+1
source

Source: https://habr.com/ru/post/1525628/


All Articles