最近在看nopCommerce项目,其中不明白它的接口的使用,它的代码如下#region Fields        private readonly IBlogService _blogService;
        private readonly ILanguageService _languageService;
        private readonly IDateTimeHelper _dateTimeHelper;
        private readonly ICustomerContentService _customerContentService;
        private readonly ILocalizationService _localizationService;
        private readonly IPermissionService _permissionService;
        private readonly AdminAreaSettings _adminAreaSettings;        #endregion #region Constructors        public BlogController(IBlogService blogService, ILanguageService languageService,
            IDateTimeHelper dateTimeHelper, ICustomerContentService customerContentService,
            ILocalizationService localizationService, IPermissionService permissionService,
            AdminAreaSettings adminAreaSettings)
        {
            this._blogService = blogService;
            this._languageService = languageService;
            this._dateTimeHelper = dateTimeHelper;
            this._customerContentService = customerContentService;
            this._localizationService = localizationService;
            this._permissionService = permissionService;
            this._adminAreaSettings = adminAreaSettings;
} #endregion 
拿接口 IBlogService  来说  一般我是这么使用的 IBlogService  _blogService  = new BlogService();  
请问我怎么用它这种方式使用
程序用MVC3写的 下面贴出部分代码
Controllers 部分namespace Nop.Admin.Controllers
{
[AdminAuthorize]
    public partial class BlogController : BaseNopController
{
#region Fields        private readonly IBlogService _blogService;
        private readonly ILanguageService _languageService;
        private readonly IDateTimeHelper _dateTimeHelper;
        private readonly ICustomerContentService _customerContentService;
        private readonly ILocalizationService _localizationService;
        private readonly IPermissionService _permissionService;
        private readonly AdminAreaSettings _adminAreaSettings;        #endregion #region Constructors        public BlogController(IBlogService blogService, ILanguageService languageService,
            IDateTimeHelper dateTimeHelper, ICustomerContentService customerContentService,
            ILocalizationService localizationService, IPermissionService permissionService,
            AdminAreaSettings adminAreaSettings)
        {
            this._blogService = blogService;
            this._languageService = languageService;
            this._dateTimeHelper = dateTimeHelper;
            this._customerContentService = customerContentService;
            this._localizationService = localizationService;
            this._permissionService = permissionService;
            this._adminAreaSettings = adminAreaSettings;
} #endregion 
        
#region Blog posts        public ActionResult Index()
        {
            return RedirectToAction("List");
        }
IBlogService 部分namespace Nop.Services.Blogs
{
    /// <summary>
    /// Blog service interface
    /// </summary>
    public partial interface IBlogService
    {
        /// <summary>
        /// Deletes a blog post
        /// </summary>
        /// <param name="blogPost">Blog post</param>
        void DeleteBlogPost(BlogPost blogPost);        /// <summary>
        /// Gets a blog post
        /// </summary>
        /// <param name="blogPostId">Blog post identifier</param>
        /// <returns>Blog post</returns>
        BlogPost GetBlogPostById(int blogPostId);BlogService 部分namespace Nop.Services.Blogs
{
    /// <summary>
    /// Blog service
    /// </summary>
    public partial class BlogService : IBlogService
    {
        #region Constants
        private const string BLOGPOST_BY_ID_KEY = "Nop.blogpost.id-{0}";
        private const string BLOGPOST_PATTERN_KEY = "Nop.blogpost.";
        #endregion        #region Fields        private readonly IRepository<BlogPost> _blogPostRepository;
        private readonly ICacheManager _cacheManager;
        private readonly IEventPublisher _eventPublisher;        #endregion        #region Ctor        public BlogService(IRepository<BlogPost> blogPostRepository, 
            ICacheManager cacheManager, IEventPublisher eventPublisher)
        {
            _blogPostRepository = blogPostRepository;
            _cacheManager = cacheManager;
            _eventPublisher = eventPublisher;
        }        #endregion        #region Methods

解决方案 »

  1.   

    你需要编写一些类,实现这些接口的方法。然后再传入它。比如
    class MyBlogService : IBlogService
    {
        public void DeleteBlogPost(BlogPost blogPost)
        {
            //添加你的代码,根据传入的blogpost对象,访问数据库,删除它
        }    ...
    }
      

  2.   

    你是想写一个自己的controller还是想实现什么
      

  3.   

    这里用了依赖解析器,由IOC容器来实例化实现了那些接口的类型
    楼主可以搜一下autofac / unity container 来找相关的资料