[英]Autofac Registration Brace
In the last days I took a watch to 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!!!! 在最后几天,我把手表带到了orchad源,在使用Autofac注册组件的过程中,我看到了相同的代码,我无法解释! 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, eg: 使用大括号围绕某些东西会创建不同的上下文,例如:
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. 在你的情况下,函数似乎没有返回任何东西,因此,上下文并不重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.