Open YegorStepanov opened 2 years ago
4.
Optional Parameters If a parameter to a type or method is optional, StrongInject will not error if it cannot be resolved, and will instead just use the default value.
An example of where this can be useful is for providing a default instance of an interface if none is registered:
public class DefaultImplementation : IInterface {} public interface IInterface {}
[Register(typeof(DefaultImplementation))]
public class Module
{
[Decorator] GetIInterface(IInterface? impl = null, DefaultImplementation defaultImpl) => impl ?? defaultImpl;
}
Not working for me:
[Register<Service>]
[Register(typeof(DefaultImplementation))]
public partial class Container : IContainer<Service>
{
[DecoratorFactory] IInterface GetIInterface(DefaultImplementation defaultImpl, IInterface? impl = null) => impl ?? defaultImpl;
}
public class DefaultImplementation : IInterface { }
public record Service(IInterface _);
// [SI0102] Error while resolving dependencies for 'Service': We have no source for instance of type 'IInterface'
Thanks for all the issues. I will look into them when I get a chance.
1)
[FactoryRegistration]
has been renamed to[RegisterFactory]
. Is Factory Registration naming outdated here?2)
[RegisterFactory]
doesn't register factory, onlyT
. Is it bug in code or outdated info in docs?:FactoryRegistration is outdated in warning too.
3) In readme:
scope
parameter should befactoryScope
instead and [RegisterFactory] doesn't have parameterType registerAs
.