场景是; VS2017、MVC 5、StructureMap.MVC5
我收到以下错误:
构建类型 BLL.MMCodes.MMCodesService 时出错。" InnerException {"值不能为空。\r\n参数名称:字符串"}
尝试运行我的应用程序时出现在“DoGetInstance”函数中。
protected override object DoGetInstance(Type serviceType, string key)
{
IContainer container = (CurrentNestedContainer ?? Container);
if (string.IsNullOrEmpty(key)) {
return serviceType.IsAbstract || serviceType.IsInterface
? container.TryGetInstance(serviceType)
: container.GetInstance(serviceType);
}
return container.GetInstance(serviceType, key);
}
服务和接口
namespace BLL.MMCodes
{
public interface IMMCodesService
{
bool ValidateAgainstBizRules(string MMCode, out string errorMessage);
bool _UseEF
{
get;
set;
}
}
public class MMCodesService : IMMCodesService
{
private string errorMessage;
public MMCodesService()
{
ValidateAgainstBizRules( MMCode, out errorMessage);
}
#region vars
public string MMCode { get; set; }
private bool IsValid { get; set; }
private List<string> Validations = new List<string>();
#endregion
public bool _UseEF { get; set; }
public bool ValidateAgainstBizRules(string mmCode, out string errorMessage)
{....}
控制器
using System.Collections.Generic;
using System.Web.Mvc;
using BLL.MMCodes;
using BusinessLayerDemoProject.Models;
namespace BusinessLayerDemoProject.Controllers
{
public class MMCodeController : Controller
{
private IMMCodesService _iService;
public MMCodeController(IMMCodesService service)
{
this._iService = service;
this._iService._UseEF = true;
}
我已经尝试了来自整个论坛的几个建议,例如。更改中的属性StructureMapDependencyScope以适应 HTTPContext 和 CurrentNestedContainer 属性中的 null,但没有成功。
人到中年有点甜
相关分类