locked
Dynamic Dll additions RRS feed

  • Question

  • I am creating an application where the main program/form works like a framework. and additions are created via dll files.

     

    overview

    the main app is static it is just there to read from the db. it must then send this data off to be formatted, where there are several ways of doing it. now while this bit is easy there is a curveball... the system will be deployed over 5 companies and each one has there own formatting needs, and will want more formatting abilities to be created as they go. with several possible ones running at a time.

     

    so a dll file for each format sounded like the way to go so that the application can find what formats there are, and how many, sort of like a plug in. So when a client wants to have a new format I can create the dll file and all they have to do is put that file into the "Templates" directory.

     

    What I can do so far is reference the dll file and use the namespace and hardcode the class name and method into the main class.

     

    What I need to do(and I am up for change in this as I might very well be approaching this wrong)

    on load run current dll files in templates directory against those already referenced, if one found to be not references then in runtime reference it.

    find some way of either dynamically editing the namespace needed to the one that that dll file uses, or find a way for this app to pick up what class is in the dll file so as to utilize the correct class and template.

    Thanks in advance for any help :D

    Monday, April 18, 2011 1:18 PM

Answers

  • Hi,

    You could load the assembly and use Reflection to get the types that are matching some condition to be usable from your own application (for example those that are implementing a particular interface, this way your main app code runs against an interface, don't have to reference any of the actual DLLs and will run against all addins implementing this particular interface).

    Depending on your usage you may want to check http://www.codeproject.com/KB/dotnet/AddInModel.aspx that explains the add-in model provided by .NET out of the box.

    Even if this is a bit too sophisticated for now for your needs, you may still want to give this in look to ease a possible switch to this model if you need at some point something that would fit this model (for a start you could reuse the same directory layout to place your own addins).

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Proposed as answer by ib.d Tuesday, April 19, 2011 4:55 AM
    • Marked as answer by Aspen VJ Wednesday, April 27, 2011 1:28 AM
    Monday, April 18, 2011 5:07 PM

All replies

  • Hi,

    You could load the assembly and use Reflection to get the types that are matching some condition to be usable from your own application (for example those that are implementing a particular interface, this way your main app code runs against an interface, don't have to reference any of the actual DLLs and will run against all addins implementing this particular interface).

    Depending on your usage you may want to check http://www.codeproject.com/KB/dotnet/AddInModel.aspx that explains the add-in model provided by .NET out of the box.

    Even if this is a bit too sophisticated for now for your needs, you may still want to give this in look to ease a possible switch to this model if you need at some point something that would fit this model (for a start you could reuse the same directory layout to place your own addins).

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    • Proposed as answer by ib.d Tuesday, April 19, 2011 4:55 AM
    • Marked as answer by Aspen VJ Wednesday, April 27, 2011 1:28 AM
    Monday, April 18, 2011 5:07 PM
  • i'll give this a try thanks Scribe :)
    Tuesday, April 19, 2011 5:59 AM
  • Hi StevenDall,

    How is your issue now? I think Patrice's reply can help you much. I will mark it temporary. If that doesn't meet your request, please feel free let us know. Thanks.


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 27, 2011 1:28 AM