创建一个具体的实现,然后注册它

时间:2015-10-13 14:55:55

标签: c# .net dependency-injection simple-injector

所有的拳头,我使用simpleInjector。

i= imread('path');
imgG= rgb2gray(i);

PSF = fspecial('gaussian',7,7);
Blurred = imfilter(imgG,PSF,'symmetric','conv');
figure ,imshow(Blurred)

edgeimg = edge(Blurred , 'canny');
figure ,imshow(edgeimg)

我有

private static readonly Container Container = new Container();

public interface ILine
{
    Guid LineId { get; set; }

    void Run();
}

现在也:

public class CallFlowApplication : ICallFlowApplication
{
    private ILine _lineApi;
    public CallFlowApplication(ILine line)
    {
        _lineApi = line;
    }

    public void HandleCall()
    {
        throw new NotImplementedException();
    }
}

当我播放应用程序时,我在代码static void RegisterDependencies() { VoiceElementsCallFlowService.Container = Container; Container.Register<ICallFlowService, VoiceElementsCallFlowService>(); Container.Register<ICallFlowApplication, CallFlowApplication>(); // TODO: Register your application here Container.Register<IApplicationFactory>(() => new ApplicationFactory { { 1, () => Container.GetInstance<CallFlowApplication>() } }, Lifestyle.Singleton); }

处收到错误
  

配置无效。为类型ICallFlowApplication创建实例失败。 CallFlowApplication类型的构造函数包含名称为&#39; line&#39;的参数。并键入未注册的ILine。请确保ILine已注册,或更改CallFlowApplication的构造函数。

我的问题是我不确定如何在这里处理Container.Verify();

1 个答案:

答案 0 :(得分:0)

使用您对netstat -a -n | find "SYN"ILine的具体实施方式注册ILine

VoiceElementsLine

当容器尝试实例化Container.Register<ILine, VoiceElementsLine>(); Container.Register<ICallFlowApplication, CallFlowApplication>(); 时,其构造函数为CallFlowApplication,但您尚未注册ILine,因此它没有任何内容给它这就是它失败的原因。您需要告诉容器&#34;嘿,当某事要求ILine给它ILine时。&#34;