What are the benefits of dynamic dll loading?

Look for the benefits of loading DLLs dynamically rather than letting your application load DLLs by default.

+6
c # dll dynamic-loading
source share
6 answers

One advantage is the support for the plugin architecture.

Suppose, for example, that you want to write a service that performs various types of tasks on a schedule. What these tasks do is not really related to your main service, which just had to let them go at the right time. And, most likely, you will want to add support for other tasks in the future (or maybe another developer wants to). In this case, by implementing the plugin approach, it allows you to drop more (interface compatible) DLLs that can be encoded independently of the main service. Thus, adding support for a new task does not require a new build / deployment of the entire service. If any specific task needs to change, you just need to reinstall the dll, and then automatically select.

It also requires that other developers do not care about the service itself, they just need to know which interface to implement so that it can be raised.

+4
source share

We use this architecture for our processing applications to handle the differences that our various clients require. Each DLL has a similar structure and implements the same interface and input method "Process ()". We have an XML file that determines which class is loaded based on the client, and whether there are more methods besides the process to be called. Performance should not be a problem until the number of transactions is very high.

+2
source share

Loading dynamic objects dynamically is a mechanism that allows ad hoc plugins to run applications. Without plugins, a modular application should be built at connection time or compilation time (look at the nginx code).

+1
source share

Your question about C # /. NET, therefore, in this world, dynamic DLL loading requires advanced programming skills. This can compensate for all the potential benefits of dynamic DLL loading. You just need to write a lot of "low level" code.

In C ++ / Win32, I often have to load DLLs dynamically when this DLL has some new API function that is not available on older operating systems. In this case, I need to ensure the availability of this API at runtime. I can’t just reference this DLL because it will lead to application loading errors on legacy operating systems.

As already mentioned, you can also get some benefits in a plugin environment. In this case, you will have more control over your resources if you load DLL files dynamically. Essentially, COM is a good example of dynamic DLL processing.

+1
source share

If you download only DLL files, then the application startup time should be faster.

+1
source share

Another reason for dynamically loading a DLL is reliability.

You can load the DLL into the so-called AppDomain. Appdomain is basically a container for sand containers in which you can put things (either parts of a DLL or an entire EXE) to work in isolation, but inside your application.

If you do not call the type contained in the AppDomain, it has no way to interact with your application.

So, if you have a dodgy third-party DLL or DLL in which you do not have source code, you can load it into AppDomain to isolate it from the main flow of applications.

The end result is that if a third-party DLL throws shaky, only the application is affected, and not your entire application.

0
source share

All Articles