Book Image

Learning NServiceBus - Second Edition

By : David Boike
Book Image

Learning NServiceBus - Second Edition

By: David Boike

Overview of this book

Table of Contents (18 chapters)
Learning NServiceBus Second Edition
About the Author
About the Reviewers

Dependency injection

Dependency injection is a pattern that allows us to avoid hardcoded dependencies and define them at runtime. NServiceBus uses dependency injection to manage a host of dependencies, but the most visible dependency is the IBus dependency, which we take in our message handlers. We just declare a public instance of an interface as a property, and at runtime, NServiceBus will inject the runtime value that provides the implementation for that interface.

By default, NServiceBus will use the Autofac container (which is embedded within NServiceBus.Core.dll) for its own needs. In most cases, this is just fine, but if you already use a DI container and would like to integrate NuGet package with it directly, you can do so using one of the following NuGet packages that act as an adapter between NServiceBus and your chosen container:

  • NServiceBus.Autofac

  • NServiceBus.CastleWindsor

  • NServiceBus.Ninject

  • NServiceBus.Spring

  • NServiceBus.StructureMap

  • NServiceBus.Unity

Each package will...