开发者

Autofac Registration Brace

开发者 https://www.devze.com 2023-03-06 22:06 出处:网络
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!!!!

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号