0
votes

I know how to register assembly in the bootstrapper by override --> protected override void ConfigureContainer()

but i want to register it on configuration file

i add the unity section to the app.confg

  <register type="namespace.Iinterface, assembly, Version=1.0.0.0, Culture=neutral"
            mapTo="namespace.class,assembly">
    <lifetime type="singleton" />
    <constructor>
      <param name="file" value="xml"/>
    </constructor>
  </register>

</container>

this class not register what I'm missing?

1
when trying to resolve it said the type not registered - shlomtzi

1 Answers

0
votes

I'm not sure I understand what you mean by "register assembly" as that's not a terminology used anywhere in the Unity library, docs, or code base. I'm guessing you simply want to load your configuration.

Assuming you're in the right config file (app.config/web.config for the application, .dlls don't have config files), then you need to:

  1. Reference Microsoft.Practices.Unity.Configuration.dll in your project.
  2. Add "using Microsoft.Practices.Unity.Configuration" to the top of the source file that contains your container initialization code.
  3. Call:

    container.LoadConfiguration();

That'll load your configuration from the default (unnamed) container element from the default section (named unity) in the default config file. If you want to vary from these defaults there's a variety of options to customize.

Container.LoadConfiguration is an extension method, so if you leave out the using statement (step 2 above) the call will not compile.