Skip to content

Cross Cutting Features

Ian Johnson edited this page Sep 9, 2017 · 4 revisions

Grace provides a number of extension points for applying configuration across all export strategies.

ImportMembers

To import all members of a specific type you can call ImportMember<T>. For more granularity supply a MembersThat filter.

// import all public properties and fields of type ILogger
container.Configure(c => c.ImportMembers<ILogger>());

// import all int properties that end with Id
container.Configure(c => c.ImportMembers<int>(MembersThat.EndWith("Id")));

ExportInitialize

Apply cross cutting initialization logic to all exports of a particular type.

// execute SomeMethod on all types that implement ISomeInterface
container.Configure(
     c => c.ExportInitialize<ISomeInterface>(instance => instance.SomeMethod());

IActivationStrategyInspector

Sometimes it's useful to inspect each activation strategy that is registered. You can manipulate things such as priority, exported types, import properties and more.

container.Configure(c => c.AddInspector(<YourInspector>));

IInjectionValueProvider

An IInjectionValueProvider can be provided and will be called for every dependency that is located allow a custom expression to be used. One example of this feature being used is by the MVC model binding support.

container.Configure(c => c.AddInjectionValueProvider(<YourProvider>));