首页 新闻 会员 周边

关于MEF实例化带参构造函数的问题。

0
[待解决问题]
    public interface IAccountContract
    {
        string Login(string account, string password);
    }

    [Export(typeof(IAccountContract))]
    public class AccountRealize : IAccountContract
    {
        public string Message;

        public AccountRealize(string message)
        {
            Message = message;
        }

        public string Login(string account, string password)
        {
            return string.Format("账户{0}通过密码{1}登陆成功!附加信息:{2}。", account, password, Message);
        }
    }

    [Export]
    public class MEFController : Controller
    {
        [Import]
        public IAccountContract AccountRealize { get; set; }

        //
        // GET: /MEF/

        public ActionResult Index()
        {
            string result = AccountRealize.Login("AAA", "123123");

            return Content(result);
        }

    }

 

如上述代码所示,我在MEFController调用类中,如何通过MEF调用到AccountRealize(string message)这个构造函数的实现,并传递参数?

MEF
遇见未知的自己的主页 遇见未知的自己 | 初学一级 | 园豆:2
提问于:2015-09-10 12:08
< >
分享
所有回答(2)
0

ImportingConstructor

jello chen | 园豆:7306 (大侠五级) | 2015-09-10 14:11

这个没用的。

支持(0) 反对(0) 遇见未知的自己 | 园豆:2 (初学一级) | 2015-09-10 18:40
0

http://stackoverflow.com/questions/2008133/mef-constructor-injection

使用带有[import]的参数

spchenjie | 园豆:202 (菜鸟二级) | 2017-05-20 16:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册