Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!!!! 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

like image 378
Marco Leo Avatar asked Dec 11 '25 17:12

Marco Leo


1 Answers

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.

like image 140
Olav Haugen Avatar answered Dec 14 '25 20:12

Olav Haugen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!