How to create a modul system for a cms?
Im building a CMS (ASP.NET C#) and I am currently looking at how to implement a module system. How is it done with most modularized systems on the web? The most important thing is that I dont want the modules messing with any of the core files.
Example of a case: I have an ajax search method that is using a webservice method named Search; how can a module "add" its search results to the result list? If the core search on开发者_JS百科ly searches webpages and I want the search to also search products in the e-commerce module, how can it add the product search, and its contents, to the original search method's return list? Is that even possible?
Ive been looking at reflection a little bit, and it seems to be useful with running module code from within the core, is that correct?
I have no experience with this kind of stuff, so a push in the right direction, and/or links/guides/tips would be very appreciated.
What you're looking for sounds very much like a plugin-based architecture. I would research some different open source projects and see how they do it, find the one that most similarly resembles what you would like to do, and use their methodology to design your CMS.
One of the largest open source, plugin-based projects is Eclipse, but I would look at some others as well.
You may also do some searches on Google for "component pattern", "module pattern", and "plugin pattern".
I agree with Topher in general.
In the context of ASP.NET and the example you gave, I think the best approach would be for all your modules to implement their own search logic, and expose it through a method. Then the search result would call the method to get the results from all components/modules in the system that implement search.
Generally you should have some kind of framework for the core system and components should be abstracted (interfaces for common functionality). An easy rule of thumb is that "a component gets called, while a framework calls components".
Since the search would be implemented differently depending on the component, it's the job of the component to implement it and the job of the framework to call the implementation.
As an end note, I think you should have an architecture for the whole system before you start thinking about concrete examples, as Topher said.
精彩评论