我有一个 C#.NET
WPF
应用程序,现在我需要注册什么(基本内核 NInject
的IoC
模式)已经使用了 BLL
和 DAL
层。
I've a c# .net
WPF
application, now i need to register something(basically kernel of NInject
IoC
pattern) that has been used by the BLL
and DAL
layer.
我想知道的入口点或类似,对于 DLL
在那里我可以把那code(内核注册)的东西。
I want to know the entry point or something like that for the dll
where i could put that code(kernel registration).
有关 WPF
部分,我用 App.xaml.cs
为 WCF
部分我用的Global.asax.cs
,因为它们是这些东西的入口点。但对于独立的DLL
,什么是他们的切入点。
For WPF
section, i use App.xaml.cs
, for WCF
section i use Global.asax.cs
as they are the entry point of these things. But what about standalone dlls
, what is their entry point.
一种方法是,我可以在我的DLL文件,实现这一目的,添加静态类,并从 app.xaml.cs
我叫BLL这种方法和登记自己内核。但是,这似乎更像是一个解决办法比的方法。
One approach is that, i could add a static class in my dll which fulfil this purpose and from app.xaml.cs
i call this method of BLL and register my kernels. But this seems more like a workaround than approach.
请指引我的东西多给点和逻辑。
Please guide me for something more to the point and logical.
容器配置在你的应用程序(如您的code称为第一时间点)的复合根完成。正如你已经说了,万一WPF中,这是App.xaml.cs.在这里,您注册的所有层的组成部分。 preferably你必须UI code在另一个程序集比App.xaml中。通过这种方式创建spplication是完全的code执行分离。
Container configuration is done in the composite root of your application (The point where your code is called the first time). As you already said, in case of WPF this is the App.xaml.cs. Here you register the components of ALL layers. Preferably you have to UI code in another assembly than the App.xaml. This way the creation of the spplication is completely separated from the execution of the code.
我建议读标记Seemans本书,这是中详细描述。
I suggest to read Mark Seemans book where this is described in detail.