Gazel uses Castle.Windsor for Dependency Injection. With Convention over Configuration capabilities of Castle.Windsor, you won't have to register your classes to use them. Every public class in module projects are automatically registered to Castle.Windsor. In this document you will find ways on how to make use of this feature.
Every public class should contain a
public constructor, in order for Castle.Windsor to register and configure them.
Every public class is registered to Castle.Windsor by their own type so that they can be injected to other classes.
Avoid creating circular dependencies as shown below;
For such cases;
- Consider refactoring your code. Two classes shouldn't depend on each other.
- If you think you have no other choice, then you can refactor code as shown below;
Public classes can also be injected using their interfaces
Injecting Multiple Implementations
If an interface has more than one implementations then you can inject all of them at once by using
There are 3 types of scope;
- Transient: For every resolution, Windsor creates a new instance.
- Request: For every request there is only one instance. After the request ends, object is disposed.
- Singleton: There is only one instance until application is shut down.
Manager and Query classes are singleton by convention and the rest are transient.
Gazel provides you with a gateway to all of the frameworks behind it. This gateway,
IModuleContext, is an abstraction layer for your business functionality to be independent of those frameworks.
For singleton objects, mainly Manager objects, we encourage you to inject them through constructor. On the other hand, if you want to create a transient object using Castle.Windsor, you can make use of
A word on Manager classes
For a class to be a manager class, name of the class should end with
Manager classes are singleton by convention.
Their purpose is to create an initial point of contact to a module and the functionality it provides. By that, we do not mean that it is a Façade layer.
Assume that there are 2 tables in your module:
Company class can be responsible for creating
Employee records under
Company records. But which class should create the first
This is where you need
Manager classes. This problem cannot be solved by persistent classes because to have a persistent object there should be a record in the corresponding table. It cannot be a query class because its only responsibility is to read data. Manager classes are responsible for creating first database record of a module.
Aside from this responsibility, you can make use of
Manager classes to provide batch operations or reporting services.