English 中文(简体)
用Windows Service使用Ninject
原标题:Using Ninject with a Windows Service

使用Ninject的视窗服务的任何良好实例? 我不敢确定我需要哪些延期。 此外,不能确定组成基础是什么? 使用Ninject的“Windows”服务在那里的任何良好实例?

最佳回答

窗口服务在依赖性注射方面与正常的指挥线应用没有很大差别。 直截了当的构成根基是Main方法。

我通常这样做的方式是,在其中建立“,并有一个模块解决我的依赖。 然后使用<代码>。 • 解决最高层的受扶养人——其他一切都来自那里:

static void Main(string[] args)
{
    var kernel = new StandardKernel(new FooModule());
    var barDependency = kernel.Get<Bar>();

    System.ServiceProcess.ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[] { new FooService(barDependency) };
    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
问题回答

Using Ninject with TopShelf.. run vs install(start) I faced a strange issue where > MyService.exe run works fine with the code Kernel.Bind(handlers => { var bindings = handlers.From("abc.dll") ... }

但在安装>后即开始服务;Myservice.exe安装

它不能解决Ninject组装扫描中所提到的约束问题。

几小时打断我的头部......

更改<代码>。 从AssembliesMatching(......) i 能够顺利开始服务。

希望能帮助他人。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签