You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can register a type implementing IFactory as a Factory Registration. This will automatically register it as both IFactory and T.
[FactoryRegistration] has been renamed to [RegisterFactory]. Is Factory Registration naming outdated here?
[RegisterFactory] doesn't register factory, only T. Is it bug in code or outdated info in docs?:
[RegisterFactory(typeof(Factory))]publicpartialclassContainer:IContainer<IFactory<int>>{}publicclassFactory:IFactory<int>{publicintCreate()=>0;}newContainer().Run(_ =>{});// leads to error: // [SI0102] Error while resolving dependencies for 'StrongInject.IFactory<int>': We have no source for instance of type 'StrongInject.IFactory<int>'//// if we add [Register(typeof(Factory), typeof(IFactory<string>))] it works fine, but there is a warning now:// [SI1001] 'Factory' implements 'StrongInject.IFactory<string>'. Did you mean to use FactoryRegistration instead?
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<Service>][Register(typeof(DefaultImplementation))]publicpartialclassContainer:IContainer<Service>{[DecoratorFactory]IInterfaceGetIInterface(DefaultImplementationdefaultImpl,IInterface?impl=null)=>impl??defaultImpl;}publicclassDefaultImplementation:IInterface{}publicrecordService(IInterface_);// [SI0102] Error while resolving dependencies for 'Service': We have no source for instance of type 'IInterface'
[FactoryRegistration]
has been renamed to[RegisterFactory]
. Is Factory Registration naming outdated here?[RegisterFactory]
doesn't register factory, onlyT
. Is it bug in code or outdated info in docs?:FactoryRegistration is outdated in warning too.
scope
parameter should befactoryScope
insteadand [RegisterFactory] doesn't have parameter
Type registerAs
.The text was updated successfully, but these errors were encountered: