Questions tagged [compositionroot]

CompositionRoot is a pattern coined by Marc Seemann in his book "Dependency Injection in .NET". It defines how to use dependency injection in applications.

19 questions
8
votes
1 answer

Does composition root needs unit testing?

I was trying to find an answer but it seems it's not directly discussed a lot. I have a composition root of my application where I create a DI-container and register everything there and then resolve needed top-level classes that gets all…
Ilya Chernomordik
  • 20,693
  • 15
  • 84
  • 144
4
votes
1 answer

Composition root in automated test of hexagonal application

I am developing an hexagonal application with BDD approach with Specflow (C# cucumber). I want to implement automated scenario system test running the core and injecting test double on the port of the inner hexagon instead of the production…
2
votes
1 answer

Implementation of Composition Root in typescript express

I am trying to understand how should I implement a composition root in a project. From what I have red, if use the composition root the wrong way (for example, by referencing it in lots of place in your application code), you will end up with the…
2
votes
1 answer

What should I code in the 'main' method?

Perhaps this is too broad a question, but I still want to hear what are the best practices and what is considered 'correct'. I did not find a similar topic, probably due to how generic it is and thus hard to search. This all began when we took a…
2
votes
2 answers

Dependency Injection - Subscribing to events in the composition root instead of the constructor

When implementing DI, both Mark Seemann, and Misko Hevery say that constructors should be simple, and should only receive dependencies. They should not do anything else. (here and here) However, often I would like to subscribe to events of the…
jmrah
  • 3,633
  • 2
  • 20
  • 30
1
vote
1 answer

Relation between Composition Root and Composer

I read Dependency Injection Principles, Practices, and Patterns and I try to figured out what actually is the difference between Composition Root and Composer. In the book their definitions are: Composition Root is a single, logical location in an…
chunk1ty
  • 169
  • 1
  • 10
1
vote
2 answers

How to new up objects when using DI

I was just watching a Dependency Injection course on PluralSight that cleared up a couple of things for me. But despite the fact that it goes over a few layers, there was also no info about what exactly is the way to go when you just have to new up…
1
vote
1 answer

Where should I create the composition root in a windows service?

In the command line exe application in the windows service app that I have, there is a main method and that's where I'm registering all the dependencies using a simple injector IoC. That's my composition root now. In the same windows service…
wonderful world
  • 8,704
  • 14
  • 76
  • 142
1
vote
2 answers

DbContext Lifetime with Depedency Injection

I'm confused about the proper way to manage my DbContext lifetime using dependency injection in my WinForms application. Right now, I have code that looks like the following static class Program { // This is the main window's controller, which…
Ben Rubin
  • 5,557
  • 3
  • 24
  • 50
1
vote
1 answer

When to compose application root in a windows service

Given a C# console application that will run as a windows service, there are sort of 2 application entry points. The first obvious one is the static void Main method. Part of the job of this method is to install something that extends ServiceBase…
danludwig
  • 45,241
  • 21
  • 150
  • 230
1
vote
1 answer

Composition root vs service locator

I've been reading about the these two approaches to resolving dependencies and found some sample code for ninject implementations. For service locator followed something like public class NinjectDependencyResolver : NinjectDependencyScope,…
1
vote
1 answer

Passing dependency injected classes vs a container into an application startup WinForm

I am working on a WinForms application which has been configured into the typical 3 layers of UI, BLL, and DAL. I created a separate project to act as the startup project. Another project was also created to act as a home made dependency injection…
1
vote
0 answers

Can you have multiple composition roots?

I have a PHP command line utility that is executed like below: tool plugin command [options]... The idea is that 3rd party plugins can be used, thus the main tool has no idea what they are. It can find them through an environment variable just like…
1
vote
2 answers

How to test whether my factories are properly bound?

Using Ninject, I have the following and wish to test using FluentAssertions: [Test] public void InterfacesEndingWithFactoryShouldBeBoundAsFactories() { // Given IKernel kernel = new StandardKernel(); kernel.Bind(services => services …
Will Marcouiller
  • 22,531
  • 19
  • 89
  • 142
1
vote
1 answer

DI in layered application with isolation

Suppose that we have three layers; UI, Business, Data. We are using DI. I don't wan't Data layer to be accessible from UI. The problem is about DI registration of Data layer. Composition root is in UI and I don't wan't to have any reference to Data…
1
2