adding code at runtime
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
todd.01011101 wrote:
I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time.
Most KISS solution I can come up with would be an application that simply polls the directory and which processes every file - getting the processor based on the extension of the files. Aw, the most KISS-way of building a processor would be a console-application that generates output, simply passing the path as an argument. Would be quite easy to maintain and extend, in any language :)
Bastard Programmer from Hell :suss:
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
Since you are planning on versioning your logic, you will run into a .NET limitation that you cannot unload code once it is loaded into an app domain[^]. This is regardless of the plug-in discovery mechanism that you choose. One way around this limitation is to run your plug-ins in separate app domains, unloading the entire app domain once you need to load the next version of a particular plug-in. Since you cannot make plain old calls across app domain boundaries, so you'll need to design your interface carefully to avoid spending excessive time serializing and deserializing parameters and return values. Here is the method I use to access items loaded into separate app domains: CreateInstanceAndUnwrap[^].
-
Since you are planning on versioning your logic, you will run into a .NET limitation that you cannot unload code once it is loaded into an app domain[^]. This is regardless of the plug-in discovery mechanism that you choose. One way around this limitation is to run your plug-ins in separate app domains, unloading the entire app domain once you need to load the next version of a particular plug-in. Since you cannot make plain old calls across app domain boundaries, so you'll need to design your interface carefully to avoid spending excessive time serializing and deserializing parameters and return values. Here is the method I use to access items loaded into separate app domains: CreateInstanceAndUnwrap[^].
I don't expect *too much* churn of the plug-ins, (1, maybe 2 in a day) and the app domain is cycled every night by default so I'm not too worried about the old plug-ins stacking up and causing memory/performance issues. (If I've misinterpreted the outcome of the limitation you described, please set me straight). That being said, thanks so much for your answer. I'm so glad I posted this here, I've got some great information, and great leads to follow. I've been reading with eyes wide open all afternoon. ;P Todd
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
You could look at writing dynamic assemblies or methods Using Reflection Emit
"You get that on the big jobs."
-
I don't expect *too much* churn of the plug-ins, (1, maybe 2 in a day) and the app domain is cycled every night by default so I'm not too worried about the old plug-ins stacking up and causing memory/performance issues. (If I've misinterpreted the outcome of the limitation you described, please set me straight). That being said, thanks so much for your answer. I'm so glad I posted this here, I've got some great information, and great leads to follow. I've been reading with eyes wide open all afternoon. ;P Todd
todd.01011101 wrote:
I don't expect *too much* churn of the plug-ins, (1, maybe 2 in a day)
Every day? Or when it occurs every 6 months it might involve 1/2? If the first then perhaps you should look into some entirely different options such as scripting.
-
todd.01011101 wrote:
I don't expect *too much* churn of the plug-ins, (1, maybe 2 in a day)
Every day? Or when it occurs every 6 months it might involve 1/2? If the first then perhaps you should look into some entirely different options such as scripting.
Yes, I meant that the maximum would be 1/2 in a day, but maybe once every few months. Certainly not 1 or 2 every day.
-
You could look at writing dynamic assemblies or methods Using Reflection Emit
"You get that on the big jobs."
Ok, but how would you know what code to create dynamically? You would still need a mechanism to define the logic so it could be created dynamically. Sorry, not a very good suggestion for the problem, there are far easier methods that are more performant.
I know the language. I've read a book. - _Madmatt
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
I have used Castle Windsor[^] to accomplish something similar. There are several other .NET inversion of control containers that may also work (StructureMap, Spring.Net, Ninject, etc.) but I don't have any experience with them. Regards, Eric
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
What about a scripting engine for the business system/ part of the business system. If you require functionality to be dynamic. It could be scripted and changed on the fly.
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
This is what I have used with one of my programs. 1: Have a page on the Internet with the latest version number. 2: When your application loads, read the Internet file version and if it is grater than your application then.... 3. You can give the user the option to upgrade now or upgrade now without prompting the user. 4: Download and run a temp upgrade.exe program. Then quit your main application. 5: The upgrade.exe will download the new version (Using the same file names and locations as the old version) 6: Run the (new) main application. 7: End the upgrade.exe program.
-
I am developing a system that I'm trying to keep as generic as possible. It is capable of implementing/executing business rules that should be defined in another file/assembly. For sake of explanation, I'll segment the idea into the "generic system" and "business system". If the "business system" were to change or require an update, then that should be possible without releasing the "generic system". Let's say the generic system monitored a folder, and if a file associated with the new version of the business code was dropped into that folder then it would be accessed, and if the version was > than the current one, then the generic code would start using it. The business code could have a factory method like GetEventProcessor(guid) that would return a delegate (from the "business system" (with a consistent signature) that is associated with the guid passed into GetEventProcessor. I'm looking for examples of or ideas about a mechanism whereby code with a defined interface can be picked up and integrated into execution of another piece of code at run time. I have found some articles about plug-in based architectures in .net. Developing this type of system is new to me, and as I peer down the barrel of this possibility, I thought I'd pose the question here in hopes of harvesting some opinionated ;) guidance, warnings and/or advice. Any ideas are welcome. Thanks Todd
Jetfire is a scripting language that does what you are asking. Check out http://jetfire.codeplex.com.