Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entry Point of a DLL

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.

I want to know the entry point or something like that for the dll where i could put that code(kernel registration).

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.

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.

like image 269
manav inder Avatar asked Jul 07 '11 10:07

manav inder


2 Answers

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.

I suggest to read Mark Seemans book where this is described in detail.

like image 134
Remo Gloor Avatar answered Sep 27 '22 17:09

Remo Gloor


C# doesn't allow to run code on assembly loading, and static class constructors are lazily executed on first access to the class. However the CLR supports a static "assembly constructor", so to speak, which is executed when the assembly is first loaded. Mind you, references are still loaded lazily unless you put in special attributes to mark a referenced assembly to be loaded eagerly.

If you want you could put a static constructor into the assembly module through ildasm/ilasm. You could probably make some scripts to automate this on build.

I didn't do this myself yet, so I can't give any examples. Though if you consider doing it I can maybe dig up some links.

like image 23
Zarat Avatar answered Sep 27 '22 18:09

Zarat