Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. adding code at runtime

adding code at runtime

Scheduled Pinned Locked Moved .NET (Core and Framework)
announcementcsharpbusinessquestion
15 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D dasblinkenlight

    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[^].

    T Offline
    T Offline
    todd 01011101
    wrote on last edited by
    #6

    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

    J 1 Reply Last reply
    0
    • T todd 01011101

      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

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #7

      You could look at writing dynamic assemblies or methods Using Reflection Emit

      "You get that on the big jobs."

      N 1 Reply Last reply
      0
      • T todd 01011101

        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

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #8

        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.

        T 1 Reply Last reply
        0
        • J jschell

          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.

          T Offline
          T Offline
          todd 01011101
          wrote on last edited by
          #9

          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.

          1 Reply Last reply
          0
          • R RobCroll

            You could look at writing dynamic assemblies or methods Using Reflection Emit

            "You get that on the big jobs."

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #10

            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

            1 Reply Last reply
            0
            • T todd 01011101

              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

              E Offline
              E Offline
              Eric W Scott
              wrote on last edited by
              #11

              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

              1 Reply Last reply
              0
              • T todd 01011101

                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

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #12

                Given your rate, 1/2 every 6 months, I doubt a generic system is going to provide an advantage.

                1 Reply Last reply
                0
                • T todd 01011101

                  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

                  T Offline
                  T Offline
                  tasteywheat
                  wrote on last edited by
                  #13

                  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.

                  1 Reply Last reply
                  0
                  • T todd 01011101

                    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

                    M Offline
                    M Offline
                    Mark AJA
                    wrote on last edited by
                    #14

                    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.

                    1 Reply Last reply
                    0
                    • T todd 01011101

                      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

                      C Offline
                      C Offline
                      Charles Wiebe and John Hansen
                      wrote on last edited by
                      #15

                      Jetfire is a scripting language that does what you are asking. Check out http://jetfire.codeplex.com.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups