我正在尝试使用MvcPluginFramework。我知道它已经过时了,但我认为会对它进行升级。但是,当我尝试将插件渲染到视图中时,我在代码中遇到了一个问题,我得到以下异常:
- $ exception"该组合产生了一个组合错误。根本原因如下。查看CompositionException.Errors属性以获取更多详细信息。\ r \ n \ r \ n1)无法创建类型为' PaypalPlugin.PayPalPlugin'的实例。因为无法选择构造函数进行构造。确保该类型具有默认构造函数或标记有' System.ComponentModel.Composition.ImportingConstructorAttribute'。\ r \ n \ r \ n的结果:无法激活部件' PaypalPlugin .PayPalPlugin'。\ r \ nElement:PaypalPlugin.PayPalPlugin - > PaypalPlugin.PayPalPlugin - > DirectoryCatalog(路径= \" C:\ Projects \ solitudeec2core \ solitudeeccore \ solitude.admin \ solitude.admin \ bin \")\ r \ n \ r \ n导致:无法导出' PaypalPlugin.PayPalPlugin(ContractName = \" Kusog.Mvc.IMvcPlugin \")'来自部分' PaypalPlugin.PayPalPlugin'。\ r \ nElement:PaypalPlugin.PayPalPlugin(ContractName = \" Kusog.Mvc.IMvcPlugin \") - > PaypalPlugin.PayPalPlugin - > DirectoryCatalog(路径= \" C:\ Projects \ solitudeec2core \ solitudeeccore \ solitude.admin \ solitude.admin \ bin \")\ r \ n" System.ComponentModel.Composition.CompositionException
我正在尝试从控制器PayPal渲染html,所以我使用了以下html帮助器标签,它会在这段代码上崩溃。
/// <summary>
/// Uses MEF to get all plugins defined and get them setup for use in the site.
/// </summary>
/// <remarks>This code does not attempt to only call SetupExtensions once for a given plugin.
/// Each time this method is called, all plugins found will have their SetupExtensions method
/// called. This is intended to be called once during application startup.</remarks>
protected virtual void refreshPlugins()
{
try
{
m_pluginsContainer = new CompositionContainer(addMefCatalogs(new AggregateCatalog()));
m_pluginsContainer.ComposeParts(this);
}
catch (CompositionException compositionException)
{
Console.WriteLine(compositionException.ToString());
}
catch (ReflectionTypeLoadException ex)
{
StringBuilder sb = new StringBuilder();
foreach (Exception exSub in ex.LoaderExceptions)
{
sb.AppendLine(exSub.Message);
if (exSub is FileNotFoundException)
{
FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
{
sb.AppendLine("Fusion Log:");
sb.AppendLine(exFileNotFound.FusionLog);
}
}
sb.AppendLine();
}
string errorMessage = sb.ToString();
//Display or log the error based on your application.
}
foreach (Lazy<IMvcPlugin, IMvcPluginData> plugin in m_plugins)
{
plugin.Value.SetupExtensions(this);
}
}
编辑2
以下是显示插件初始化的结构
using Kusog.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace PayPal.Controllers
{
[DynamicActionFilter]
public class PayPalController : Controller
{
public ActionResult Index()
{
return View("~/Views/Paypal/Index.cshtml");
}
public ActionResult PageFooter()
{
return Content("");
}
}
}
编辑3
PayPalPlugin.cs
{
/// <summary>
/// Provides basic plugin functionality to show how to set it up.
/// </summary>
/// <remarks>This plugin inherits from DemoAppPlugin rather than BaseMvcPlugin because it wants to use extended functionality made available in DemoAppPlugin, such as adding menu items.
/// If a plugin doesn't need to do things other than what is provided in BaseMvcPlugin, it should inherit from that to be usable in other implementations of the plugin framework.</remarks>
[Export(typeof(Kusog.Mvc.IMvcPlugin))]
[MvcPluginMetadata("PayPalPlugin", null, "PayPalPlugin", "This is a plugin to be used for Solutide E-Commerce Platform to allow Paypal.")]
public class PayPalPlugin : DemoAppPlugin
{
public override void SetupExtensions(IMvcPluginApplication app)
{
base.SetupExtensions(app);
addLocalCss("/Content/simple.css");
addFooterScript("ksgSimple", "/Scripts/ksgSimple.js", null);
AddActionFilter("Index", "PayPalPlugin", new ActionExtension("Index", "PayPal"));
AddActionFilter("Metatags", "PluginDemo", new ActionExtension("Metatags", "Simple"));
}
}