Search code examples
c#constructorunity-containerconstructor-injection

Unity Application Block - Constructor injection in configuration file


How can I specify that constructor with no parameter should be used while creating the object? I know how to do it for the parameterized one but cannot find any help for the parameter less constructor.

I know how to do this through code but need solution for doing it through configuration.


Solution

  • Could you just specify an empty constructor node in the config?

    <types>
        <type type="MyProject.IRepository, MyProject, Version=1.0.0.0, Culture=neutral"
              mapTo="MyProject.DefaultRepository, MyProject, Version=1.0.0.0, Culture=neutral">
            <lifetime type="transient" />
            <typeConfig>
                <constructor>
                </constructor>
            </typeConfig>
        </type>
    </types>