Reputation: 5162
I have a class like:
public class CustomDatabase : Database
{
public CustomDatabase(string connString, ILogger logger)
{
}
}
for example I can use the following config section to config a type and constructor parameters
<type type="Database" mapTo="UnityExamples.Common.CustomDatabase, UnityExamples.Common">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
<constructor>
<param name="connString" parameterType="System.String">
<value value="connection value..."/>
</param>
<param name="logger" parameterType="ILogger">
<dependency />
</param>
</constructor>
</typeConfig>
</type>
But how can I convert this section into pure C# code configuration?
Upvotes: 0
Views: 611
Reputation: 6806
Try the following
container.RegisterType<Database, CustomDatabase>(new InjectionConstructor("someConnectionString", typeof(ILogger)));
Upvotes: 1