-
Notifications
You must be signed in to change notification settings - Fork 19
Composition
Clide has a built-in composition engine that automatically provides dependency injection and component discovery for all your extension types. The composition is based on the Common Composition package, configured to use the MEF implementation.
Therefore, any public or internal type in your extension that has a public constructor and is annotated with the [Component] attribute will automatically be available to all other components, such as commands:
[Component]
internal class ServerConnection : IServerConnection
{
public event EventHandler Connected;
public ServerConnection(IDevEnv devEnv)
{
...
}
}
If you want the components to be treated as singletons, just specify so via the
[Component(true)]
attribute overload.
Note how components can depend on other components or Clide built-in services. Also, true to Common Composition principles, the amount of annotation is minimal. You don't need MEF's [ImportingConstructor], [Export] or anything else. Components are registered with their type as well as their implemented interfaces, so in the above example, another component could take a constructor dependency on IServerConnection and have it automatically resolved to the implementation above.