|
|
Domain Language
The concepts of scope, tags, context & nested containers may be expressed in a way that makes it easier for a new user to grasp.
Scope, Sharing, Context, Tags
BeginScope() would be a better name for CreateInnerContainer() but the term Scope is already applied to 'sharing' in Autofac.
Could FactoryScoped() et al become NotShared(), GloballyShared(), SharedWithinContext(contextTag) and SharedWithinContainer().
BeginContext() is another possibility, but inner containers enforce visibility too, so it is more natural to make the analogy with lexical scope in a programming language.
Extended Reflection Activator
ReflectionActivator could be more extensible for purposes of constructor selection or implementation type substitution. Aim to require as little down-casting as possible when working with a specific activator.
Reconsider Exposing IContainer on Scope
Nested containers/scope are currently full containers with their own registrations etc. This makes for some clunky algorithms when resolving a previously unrequested service. A cleaner/lighter/faster implementation would be possible if they were based on IContext.
Consider use cases such as 'client specific components' that may be better supported with dynamic features like tags/matching.
Extend Parameter Abstraction
Parameters are currently named values. It may be possible to implement positional or resolvable parameters by making Parameter a more useful abstract base class.
XML Configuration Enhancements
Named parameters (based on parameter abstraction above.) Explicit specification of types for use with type converters (currently implies this information from the injection site.) Array syntax. Explicit constructor selection.
More Obvious Way to do Conditional Registration
Note issue 68 (better name for DefaultOnly().) This is accompanied by the OnlyIf() registration.
Most natural way to achieve these is through a module, but this isn't as discoverable. May consider merging Container and ContainerBuilder yet again, but this takes us back to either having endlessly mutable registrations, or having a syntactic terminator in the registration DSL.
Ummm... what about OnlyIfNotRegistered() (instead of DefaultOnly()?)
Transparent Decorators
One cool thing that is enabled by the availability of component ids (separated from their names) is that a decorator can assume the name of the decorated component and still retrieve instances of the decorated component by its id.
E.g. in a container where names are ids, you have to call the decorated component something different, like "real-thingy" and then call the decorator "thingy". This requires some forethought and doesn't give you the option of decorating something that was configured inside a programmatic module.
In Autofac you should be able to say 'decorate thingy' and have the configuration code find the id of the component with the name "thingy" so that the decorator can assume the name "thingy" while still referring to the old component by id. Nice and transparent.
First class decorator support in the API seems like a good thing. E.g. builder.Decorate<IFoo>(foo => new DecoratedFoo(foo)). To do this well, either the original component's activator would be decorated, or the additional decorator component would need to have the same scope (sharing) as foo. Next item addresses an issue currently holding that back.
Eliminate/Hide IScope
The extension point that allows traditional per-thread or per-request sharing is not being used. Removing/hiding it and promoting the InstanceScope enum to the core API will make it easier to reason about registrations reflectively (i.e. instead of downcasting !IScope, compare enum values.)
Use Configured Reflection Activator when doing Property Injection
E.g. see issue 62.
Optimise Reflection Activator when Suitable
Autofac doesn't cache constructor searches in order to behave correctly in light of dynamic registrations. Many components will use the same ctor throughout an execution, so perhaps:
builder.Register<Foo>().WithCachedActivator();
...or similar would be handy for micro-optimisations in some heavy usage scenarios.
Sign in to add a comment

Consider merging Autofac.Builder namespace into Autofac namespace? ContainerBuilder? into container?
It would be great if RegisterGeneratedFactory? could be made available in .net 2.0.
The ability to set properties directly on the type being injected to avoid using strings to define property names would be nice. Maybe something a bit like this?
builder.Register<IFoo>().WithProperties?(delegate(IContext c, IFoo target) {
});//...
container.InjectProperties?<IFoo>(foo);
Handling InjectPropertiesIfUnset? would be a little less trivial.
Hi Mads,
What you've described is already available, though it could be improved.
If you're using delegate activators, you just set properties on the instance before returning it from the delegate (strong typing.)
If you're using the reflection activator, you can still do this by handling the OnActivating? event:
builder.Register<Foo>().OnActivating?((sender, e) => {
});Equally strong typing, the cast is an unfortunate syntactic artifact but is necessary at least through the base API. An OnActivating?<T> overload would ease this up.
I vote for XML Configuration Enhancements with some array-element-syntax maybe inside a property:
and referencing other previously registered components.