dimanche 6 septembre 2020

C# Autofac DI Func factory without register Func?

I'm not sure whether SO is the correct place to ask the question, but existing SO questions don't help much(such as Autofac and Func factories), nor does Autofac document help, and google searching autofac factory func couldn't get the answer either. I have basic knowledge of DI and IoC.

The primary goal was trying to understand a ~1k stared github repo ReactiveTrader, whose main purpose was to demonstrate using reactive extension in real world application. While reading the code, I was stucked by several constructors injection like this:

public SpotTilesViewModel(IReactiveTrader reactiveTrader,
    Func<ICurrencyPair, SpotTileSubscriptionMode, ISpotTileViewModel> spotTileFactory,
    IConcurrencyService concurrencyService,
    ILoggerFactory loggerFactory)

there's a Func<TSource1, TSource2, TTarget> called somefactory in the constructor, there's no explicit reference to the constructor(so it must be DI right?), and there's no code registering the Func type(which is used in above SO answer I mentioned):

builder.RegisterType<Func...

So I'm very curious about why such Func<> factory in constructor is useful, and how does it work, and if possible, could you give a simplest demo? Many thanks!

Aucun commentaire:

Enregistrer un commentaire