This is a re-start of an email conversation from a couple weeks back. The recommendation was to start with the Forums, so here I go. Note that I'm trying to simplify this as much as I can so some of this isn't entirely representitive of how we are implementing this...
One of the parts of our to-be system involves sending messages to users as they are ordering a product. Our products are complex so there are LOTS of potential messages... say 100-400 unique messages per product. Messages are more than just text for us because they have override levels (security), one or more controls on the screen they relate to (for visual color-coding) and the text in the message needs to be built dynamically. For example, we might have a user enter a Size that is too big to manufacture. Instead of just saying "Size is too big" we want to say "The requested size of [XXXX] is larger than our maximum size of [YYYY]." In this case, the size they entered needs to be put in on the fly AND the maximum size might vary depending on the way they've configured the item they are ordering. Finally, the logic to determine whether or not to show the message can be very complex.
This is where VSTA comes in. We are planning to use VSTA to address the building of the message text dynamically as well as the logic to determine whether or not to show the message. Here's the plan...
At run time, we instantiate a collection of all potential Message Objects. As the user interacts with the order entry screen, we loop through each message and fire an event [OnEvaluate()] so the object can evaluate whether it should display. The event sets a property on the Message [.Display() AS Boolean]. We then check this Property and if it's true we fire another event [OnDisplay()] to build the text of the message and stuff it into another property [.MessageText() As String]. Finally, we use that .MessageText() and several other properties to send the message to the UI.
So far, this is nothing too crazy. The question comes in when we look at how to structure the AddIns. There seem to be three general approaches to the problem. I'll describe each along with advantages/disadvantages.
1) Create one AddIn for each Message. In this scenario, each Message object would be the one and only Primary Host Item in it's dedicated AddIn project/dll. This is very clean in terms of isolating the code for a message to one class file and the class file would have just two events in it. Very user friendly. The down side is that I'll have to load up hundreds of addin's for a user to order a product. Maybe not a big deal except that we are running a web order entry system that is being used by a couple hundred users at a time. This concerns me from a performance and stability perspective.
2) Create one AddIn for the Product. Here, we would have our Primary Host Item be some sort of Product object. This Product object would be the one and only Primary Host Item in the AddIn project. We would then have the two events (OnEvaluate and OnDisplay) declaired directly in the Prouct class. Then we would call these events over and over as we looped through all the messages, passing in some sort of MessageEventArgs that helped the event know what message was being evaluated. The advantage to this approach is that I only have to load one AddIn/Dll for each user/product, which should perform quite well. Unfortunately there is a HUGE disadvantage in having logic for 100-400 different messages all put into one event handler. With so many messages, this aproach is really not realistic for business users to manage.
3) Create one AddIn for the Product with one Host Item for each message. This is a blended approach where we have one AddIn and it's Primary Host Item is some sort of Product Class. When the AddIn Developer is in design time and creating messages, we add a Host Item Class File to the AddIn Project for each message they create. When they go to write code for the two events on each message, they will be added to the Class File that is dedicated to that unique message. This provides all the code isolation benefits of approach #1 while having the single AddIn/Dll performance and stability benefits of #2. The only unknown is creating an AddIn project with hundreds of class files. I guess my experience is to trust the compliler's ability to deal with lots of class files more than I trust the Run Time to handle loading and unloading 1000's of dlls.
I'm sure it's apparent that #3 is my current opinion, but I want to be sure there aren't known or suspected issues with this approach. Or, if #1 with all those little AddIn dll's is really nothing to be concerned about because there another disadvantage for #3. We support versioning, check-in/out and environment support for each message. This means that having them all wrapped up in one AddIn isn't that simple. In reality, at run time I'm going to have to go out to the DB and get the current version of all those messages, grab their code, re-construct the AddIn Project, compile it and then load the AddIn Dll. If I went with #1 I could have each message version's AddIn pre-compiled and just load the ones that are active at the moment.
Opine away!