-
Notifications
You must be signed in to change notification settings - Fork 31
Fluent Configuration
Ian Johnson edited this page Jan 19, 2014
·
15 revisions
The fluent interface has a number of different ways to export types and assemblies for export.
- Export<T>() - used to export a single type for one or more interfaces. Because this method is generic it allows for lambdas to be used to specify importing of properties and method.
container.Configure(c => c.Export<SomeType>().As<ISomeInterface>());- Export(Type type) - used to export a single type when it's not possible to use the Generic interface. One reason to use this method would be to register an open generic type, another use could be that you don't know the type you are going to register till runtime
container.Configure(c => c.Export(typeof(SomeType)).As(typeof(ISomeInterface)));-
Export(IEnumerable types) - used to register multiple types in one pass.
-
ExportInstance<T>(ExportFunction<T> instanceFunction) - using this method you can provide a function that will be used to export rather than allowing the framework being involved. This is the preferred way to export a type using a function.
container.Configure(c => c.ExportInstance((scope,context) => new SomeType()).As<ISomeInterface>());- ExportInstance<T>(T instance) - this method can be used to export a specific instance under a particular interface or name.
container.Configure(c => c.ExportInstance(someInstance).As<ISomeInterface>());- ExportFunc<T>(ExportFunction<T> exportFunction) - using this method you can specify how an object is constructed. It's only recommended to use this method if you need to construct and object and then specify automatic property injection or method injection.
container.Configure(c => c.ExportFunc((scope,context) => new SomeType()).As<ISomeInterface>());- SimpleExport<T>() - using this method you can export a type as a specific name. As the name implies this method only support simple constructor injection and not property injection nor method injection. It's designed to be used when registration time is import, most of the time registration is done at start up as a one time cost. SimpleExport is designed to be used when you are registering an export on each request (such as in Nancy per request setup).
container.Configure(c => c.SimpleExport<SomeType>().As<ISomeInterface>());- **SimpleExport(Type type)**using this method you can export a type as a specific name. As the name implies this method only support simple constructor injection and not property injection nor method injection. It's designed to be used when registration time is import, most of the time registration is done at start up as a one time cost. SimpleExport is designed to be used when you are registering an export on each request (such as in Nancy per request setup).
container.Configure(c => c.SimpleExport(typeof(SomeType)).As<ISomeInterface>());- AddExportStrategy(IExportStrategy exportStrategy) - this method allows the developer to provide their own export strategies to the container. Most developers will never need to use this but it's here just incase.
container.Configure(c => c.AddExportStrategy(exportStrategy));