DryIoc中的autofac .OnActivated是什么?

问题描述 投票:1回答:1

从Autofac切换到DryIoc时,我需要实现类似于OnActivated的东西。

提供以下课程

public interface IService
{
    void DoStuff {}
}
public class SomeService : IService
{
    public void DoStuff() {}
    public void Init(){}
}

我的autofac注册看起来像这样

builder.RegisterType<SomeService>()
     .As<IService>()
     .OnActivated(x => x.Instance.Init())
     .SingleInstance();

在DryIoc中这相当于什么?

autofac dryioc
1个回答
1
投票

RegisterInitializer将是最接近的等价项,请检查docs

但是它只是非常强大的DryIoc Decorators之上的糖。因此,我建议更深入地研究它们。

© www.soinside.com 2019 - 2024. All rights reserved.