IComponentActivator Instance
How can I use an IComponentActivator instance for a component, not just specifying a type.
That is, instead of
Component.For<XYZ>.Activator<MyComponentActivator>();
I want to be able say
Component.For<XYZ>.Activator(new MyComponentActivator(someImportantRuntimeInfo));
Also, is there a way I can choose an activator dynamically for a non specifically registered component? That is, I want to have an activator that looks at the type being resolved, decides if 开发者_运维技巧it can activate it, and if not, responsibility for activation should be passed on to the default activator.
So basically I want a global IComponentActivator that has the following logic:
Create(Type type){
if (ShouldActivate(type)){
DoActivate(type);
}
else{
// do default activation here somehow
}
}
Thanks!
EDIT
Just use ILazyComponentLoader
- Activators are instantiated by the container, and there is no way to provide instances OOTB.
If you really want to do this, I'd say you can extend the container itself.
- Put your custom instace activators in
ExtendedProperties
of your component under a well-known key - inherit from
DefaultKernel
- Override
CreateComponentActivator
method In there return the activator from
ExtendedProperties
of the component- There's no way to create global activator. You can add
IContributeComponentModelCreation
implementation that switches the activator to some custom one wen creating your component if you really want to.
- There's no way to create global activator. You can add
But the most important question is this:
What are you trying to achieve by this? Why do you want to do this in the first place?
精彩评论