Is it possible to specify how to resolve a class with a constructor that has a default argument?
Take the following example
init(argument1: Foo, argument2: Bar = Bar())
{
...
}
Registering it without specifying the constructor will fail during runtime, as the resolver does not assume the default argument, hence, does not recognize the registry
container.autoregister(MyClass.self, initializer: MyClass.init)
//This will fail
container.resolve(Myclass.Self, argument: Foo())
Registering it specifying a constructor will not work, as it will fail during compile time, as it cannot recognize an init that has only 1 argument
The only way I could think of, to resolve this issue, is to explicitly create a convenience init that takes argument1 and internally invokes the intended init, passing argument2 with the intended default value.
Is it possible to specify how to resolve a class with a constructor that has a default argument? Take the following example
Registering it without specifying the constructor will fail during runtime, as the resolver does not assume the default argument, hence, does not recognize the registry
Registering it specifying a constructor will not work, as it will fail during compile time, as it cannot recognize an
init
that has only 1 argumentThe only way I could think of, to resolve this issue, is to explicitly create a convenience init that takes
argument1
and internally invokes the intendedinit
, passingargument2
with the intended default value.Is there any other way to achieve this?