Ho bisogno di puntare a un metodo in collegamenti Ninject come parte di un argomento costruttore. Il costruttore della classe appare così:Ninject Pass Delegate in WithConstructorArgument
MyObject(Func<Populator> param1, TimeSpan time)
ho cercato e non sono stati in grado di trovare un modo per associare il delegato per il Funz. È possibile? Ninject non mi consente di farlo perché prevede un oggetto come argomento e non accetta un delegato.
Bind<IInterface>()
.To<MyObject>()
.InSingletonScope()
.WithConstructorArgument
("param1", ctx => ctx.Kernel.Get<OtherWiredObject>().PopMethod)
.WithConstructorArgument
("time", new TimeSpan(0,30,0));
C'è un modo per far funzionare questo comportamento in Ninject?
che sovraccaricare sembra essere per una funzione di callback. Cosa succede se hai fatto '() => Kernel.Get(). PopMethod'? –
dotjoe
Nessun dado, cablato come '() => Kernel.Get(). PopMethod' Guardando la firma del metodo WithConstructorArgument per questo, Func si aspetta un oggetto da restituire, e ho bisogno di restituire un Func a il parametro. Forse c'è un altro modo per aggirare questo? –
è 'PopMethod' una proprietà di tipo' Populator'? – dotjoe