Autofac Registration Brace
In the last days I took a watch t开发者_运维百科o the orchad source, and in the bootstrap class during the registration of the components with Autofac I saw same code that I can't explain!!!! I will provide an example:
builder.RegisterType<A>().As<IA>();
{
builder.RegisterType<B>().As<IB>();
{
builder.RegisterType<C>().As<IC>();
}
}
I can't undstand what the brace do? Is it like a sub registration??
Hope somebody can help me!
Thanks
This would be no different than writing:
builder.RegisterType<A>().As<IA>();
builder.RegisterType<B>().As<IB>();
builder.RegisterType<C>().As<IC>();
Surrounding something with braces creates a different context, e.g:
int a = 1;
{
int b = 2;
}
// b not accessible from here
In your case, the function doesn't seem to return anything, and therefore, context doesn't really matter.
精彩评论