Situation: We have several classes, which are registred as interface. Also this classes are marked with custom attribute. We want to go throught all registered components in the end of App containew building and create new registrations based on ot. For example,
[CustomAttribute]
public class Foo: IFoo
{
[NewCustomActionAttribute("Show me your power!")]
public void Do() {}
}
So we are doing this – builder.Register<Foo>.As<IFoo>();
And a lot of the similar classes into another plugins. After all plugins beeing registered, we want to add new class to builder, e.g. ICustomAction with some metadata like caption and module, and load it later based on this registration.
What is the best way to do that?
UPDATE:
var types = // get all registered types
foreach (var typeToProceed in types.Where(_ => _.GetCustomAttributes(typeof(CustomAttribute), false).FirstOrDefault != null)
{
var customMethodAttributes = // Get NewCustomActionAttributes from this type
for each customAttr
builder.Register(new CustomClass(customAttr.Caption, dynamic delegate to associated method);
end for aech
}
I do not want to do it in the vase bootstrap, because there may be a lot of another attributes. The best way is to add (only once) new classes when this item (Toolbar) is requsted first.
I would create a new extension method
RegisterCustomClassesthat handles the registration:Usage: