Osgi. net plug-in framework can be applied to any.. NET application environment, provides a unified modular, SOA, and extended plug-in development model, and can release plug-in updates through the plug-in repository to achieve automatic upgrade of plug-ins and unified application deployment. Now let's take a look at developing ASP. net mvc plug-in applications using osgi. net.
1. Preparations
Go to the iopenworks website http://www.iopenworks.com/download osgi. Net plug-in framework, you can download the plug-in framework from the address below: http://www.iopenworks.com/products/sdkdownload. After the download is complete, install the SDK. The SDK supports VS 2005/2008/2010. Currently, support for vs2012 is under development.
Next, you can download an empty ASP. net mvc 3.0 master from the following addressProgram:/Files/unzip hmpgy/unzip mvcosgi.zip. This is a demo of ASP. net mvc plug-in.
2. Obtain a Main Interface
After installing the osgi. Net Plug-In SDK, use vs 2010 to open the downloaded ASP. net mvc 3.0 main program, press F5 to run the project, and enter the plug-in Center page. Select "win7 web interface framework ".
Next, click "download and install application". The following shows the download progress and the prompt for the final installation interface.
At this time, you can find that we already have a Windows 7-style Web interface.
3. Develop ASP. net mvc plug-in
Next, we will first create an ASP. net mvc plug-in project, followed by the empty MVC project.
Next, we need to add a plug-in description list file manifest. XML for this plug-in project. The content of this file is as follows. Here, the symbolicname of the plug-in is declared as helloworldplugin2, which declares a local assembly helloworldplugin2.dll.
<? XML version = "1.0" encoding = "UTF-8" ?> < Bundle Xmlns = "Urn: uiosp-bundle-manifest-2.0" Symbolicname = "Helloworldplugin2" > < Runtime > < Assembly Path = "Helloworldplugin2.dll" /> </ Runtime > </ Bundle >
Next, we need to change web. config to delete some content that conflicts with the main program.
View code
<? XML version = "1.0" ?> < Configuration > < System . Web > < Compilation Debug = "True" Targetframework = "4.0" > < Assemblies > < Add Assembly = "System. Web. Export actions, version = 4.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35" /> < Add Assembly = "System. Web. helpers, version = 1.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35" /> < Add Assembly = "System. Web. Routing, version = 4.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35" /> < Add Assembly = "System. Web. MVC, version = 3.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35" /> < Add Assembly = "System. Web. webpages, version = 1.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35" /> </ Assemblies > </ Compilation > < Pages > < Namespaces > < Add Namespace = "System. Web. helpers" /> < Add Namespace = "System. Web. MVC" /> < Add Namespace = "System. Web. MVC. Ajax" /> < Add Namespace = "System. Web. MVC. html" /> < Add Namespace = "System. Web. Routing" /> < Add Namespace = "System. Web. webpages" /> </ Namespaces > </ Pages > </ System. Web > </ Configuration >
Next, we add a controller and a view with the default content.
Next, edit the _ viewstart. cshtml file in views and change the layout path.
@ {Layout = "~ /Plugins/helloworldplugin2/views/shared/_ layout. cshtml ";}
Next, let's change the manifest. xml file and register the index action of hellocontroller of the current MVC plug-in to the interface framework, which can be accessed directly through the win 7 Web interface framework.
<? XML version = "1.0" encoding = "UTF-8" ?> < Bundle Xmlns = "Urn: uiosp-bundle-manifest-2.0" Name = "MVC plug-in 2" Symbolicname = "Helloworldplugin2" > < Runtime > < Assembly Path = "Helloworldplugin2.dll" /> </ Runtime > < Extension Point = "Uishell. webapplications" > < Application Tooltip = "MVC plug-in 2" Icon = "/{Bundlerelativepath}/images/application.png" Defaultpage = "/Helloworldplugin2/hello" Windowstate = "Maximized" > < Navigationnode Text = "List movies" Tooltip = "List all movies" Imageurl = "/{Bundlerelativepath}/images/application.png" Navigateurl = "/Helloworldplugin2/Hello/Index" /> </ Application > </ Extension > </ Bundle >
Now let's run the project. At this time, you can find that the MVC plug-in icon has already appeared on the main interface. Double-click the main interface to open the index page of the MVC plug-in by default. You can download the content of the current plug-in project from the following address:/files/baihmpgy/2_mvcosgi_emtyplugin.zip.
Next, we will add more content to helloworldplugin2 as well as the page. At this time, our hellocontroller ControllerCodeAs follows, it defines the CREATE/edit/save/delete action for the movie record.
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. Web; Using System. Web. MVC; Using Helloworldplugin2.models; Namespace Helloworldplugin2.controllers { Public Class Hellocontroller: controller { Public Actionresult index (){ VaR Model = New Movielist (); Return View (model. getmovies ());} Public Actionresult createnew (){ VaR Model = Movie. newmovie (); Return View (model );} Public Actionresult savenewmovie (movie ){ VaR Model = New Movielist (); Model. getmovies (). Add (movie ); Return Redirecttoaction ( " Index " );} [Httpget] Public Actionresult editmovie ( Int ID ){ VaR Model = New Movielist (). getmovies (). Find (P => P. ID = ID ); Return View (model);} [httppost] Public Actionresult editmovie (movie ){ VaR Model = New Movielist (). getmovies (). Find (P => P. ID = Movie. ID); Model. Name = Movie. Name; model. Rating =Movie. rating; Return Redirecttoaction ( " Index " );} Public Actionresult deletemovie ( Int ID ){ New Movielist (). getmovies (). Remove ( New Movielist (). getmovies (). Find (P => P. ID = ID )); Return Redirecttoaction ( " Index " );}}}
Now, run the project again, as shown below. Here, you can add, modify, or delete a movie record. You can download the current plug-in Project:/files/unzip hmpgy/3_mvcosgi_helloworldplugin2.zip.
4. create other MVC 3 plug-ins
Similarly, we can create an MVC plug-in -- helloworldworldin. You can download the current content of the project at the following address:/files/unzip hmpgy/4_mvcosgi_moremvcplugins.zip. You can directly access the plug-in through the web interface framework.
Of course, you can also directly access the page through http: // localhost: 35718/helloworldplugin2/Hello/index, the URL routing rule is {plugin}/{controller}/{action }.
In this case, the factory remote management tool can be opened and 10 plug-ins are available. Here, you can start/stop/uninstall the plug-ins loaded by the kernel.
Source code:
/Files/unzip hmpgy/unzip mvcosgi.zip
/Files/export hmpgy/2_mvcosgi_emtyplugin.zip
/Files/export hmpgy/3_mvcosgi_helloworldplugin2.zip
/Files/export hmpgy/4_mvcosgi_moremvcplugins.zip