Reputation: 3120
If I don't have the concrete class mapped to the interface, when Unity tries to resolve the type it gives me this error: "The current type, IFoo, is an interface and cannot be constructed. Are you missing a type mapping?".
However, for testing purposes, I'd like Unity to pass null to the interfaces that aren't mapped yet to concrete types.
Any suggestion to make this as the default behavior to "resolve" unmapped interfaces?
Thanks
Upvotes: 3
Views: 1722
Reputation: 3120
I could let Unity pass null to my dependencies using the OptionalParameter while configuring the constructor injection.
container.RegisterType<IObject, MyObject>(
new InjectionConstructor(
new OptionalParameter<IFoo>()
)
);
Upvotes: 1