我使用本教程在我的解决方案中创建插件架构,并且我也是第一次使用 ninject:
现在在 MVC 应用程序中,当用户正在结帐时,我得到了他选择的付款方式,并且需要检索所选付款方式的插件。我已经成功地以这种方式检索插件控制器,但我不知道这是否安全或可接受的做法:
Type type = Type.GetType(paymentMethod.PaymentMethodPluginType);
//get plugin controller
var paymentController = ServiceLocator.Current.GetInstance(type) as BasePaymentController;
//get validations from plugin
var warnings = paymentController.ValidatePaymentForm(form);
//get payment info from plugin
var paymentInfo = paymentController.GetPaymentInfo(form);
//…
我还需要访问一个插件类来处理付款。我有一个接口 IPaymentMethod
public partial interface IPaymentMethod
{
void PostProcessPayment (PostProcessPaymentRequest postprocessPaymentRequest);
}
和插件 PaymentProcessor 像这样
public class PluginPaymentProcessor :IPaymentMethod
{
public void PostProcessPayment (PostProcessPaymentRequest postprocessPaymentRequest)
{
///
}
Now in MVC project I try to access PostProcessPayment method this way
IPaymentMethod pluginpaymentmethod = ServiceLocator.Current.GetInstance<IPaymentMethod>(paymentMethod.PaymentProcessor);
这里 paymentMethod.PaymentProcessor 是“MyApp.Plugins.MyPlugin.PluginPaymentProcessor, MyApp.Plugins.MyPlugin,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”</p>
And want to use pluginpaymentmethod like i do in controller example
pluginpaymentmethod.PostProcessPayment(postProcessPaymentRequest);
但它会引发错误,即找不到资源并且未加载 pluginpaymentmethod。我该如何解决它,或者您可以建议任何具有类似实现的教程?谢谢你。