Automatic registration

In recent days, I took a clock to the orchad source, and in the bootstrap class during the registration of components with Autofac I saw the same code that I can not explain !!!! I will give an example:

builder.RegisterType<A>().As<IA>();
{
  builder.RegisterType<B>().As<IB>();
  {
     builder.RegisterType<C>().As<IC>();
  }
}

I can not understand what the bracket does? Does this look like a re-registration?

Hope someone can help me!

thank

+3
source share
1 answer

This is no different from writing:

builder.RegisterType<A>().As<IA>();
builder.RegisterType<B>().As<IB>();
builder.RegisterType<C>().As<IC>();

Surrounding something with curly braces creates a different context, for example:

int a = 1;
{
    int b = 2;
}
// b not accessible from here

In your case, the function does not return anything, and therefore the context does not matter much.

+5
source

All Articles