2014-04-10 8 views
0

일부 핵심 기능을 두 번째 코드 라이브러리로 분할하는 코드를 리팩터링했습니다. 이것의 일부로, 인터페이스를 2 개로 분할했습니다. 다음은 어떻게 사용했는지 보여줍니다.'IMyInterface'에 'MediaExists'에 대한 정의가 없습니다. 의미가 없습니다.

namespace Ministry.Ministryweb.Repositories 
{ 
    public interface IMinistrywebPublishedContentRepository 
    { 
     /// <summary> 
     /// Gets the media item. 
     /// </summary> 
     /// <param name="id">The id of the item.</param> 
     /// <returns></returns> 
     IPublishedContent MediaItem(int id); 

     /// <summary> 
     /// Gets the umbraco helper. 
     /// </summary> 
     UmbracoHelper Umbraco { get; } 

     /// <summary> 
     /// Determines if a piece of media exists. 
     /// </summary> 
     /// <param name="mediaId">The media id.</param> 
     /// <returns></returns> 
     bool MediaExists(int? mediaId); 

     /// <summary> 
     /// Gets the URL for some media content. 
     /// </summary> 
     /// <param name="mediaId">The media id.</param> 
     /// <returns>A nicely formed Url.</returns> 
     string MediaUrl(int? mediaId); 

     /// <summary> 
     /// Gets the content URL. 
     /// </summary> 
     /// <param name="nodeId">The node id.</param> 
     /// <returns>A nicely formed Url.</returns> 
     string ContentUrl(int nodeId); 

     /// <summary> 
     /// Returns the content at a specific node. 
     /// </summary> 
     /// <param name="id">The node id.</param> 
     /// <returns>Dynamic content.</returns> 
     dynamic Content(int? id); 

     /// <summary> 
     /// Gets the blog roll. 
     /// </summary> 
     IBlogRoll BlogRoll { get; } 

     /// <summary> 
     /// Gets the root ancestor. 
     /// </summary> 
     IPublishedContent RootAncestor { get; } 

     /// <summary> 
     /// Gets the consultancy URL. 
     /// </summary> 
     string ConsultancyUrl { get; } 

     /// <summary> 
     /// Gets the development URL. 
     /// </summary> 
     string DevelopmentUrl { get; } 

     /// <summary> 
     /// Gets the team management URL. 
     /// </summary> 
     string TeamManagementUrl { get; } 

     /// <summary> 
     /// Gets the name of the root ancestor. 
     /// </summary> 
     string RootAncestorName { get; } 

     /// <summary> 
     /// Gets an article with the specified ID. 
     /// </summary> 
     /// <param name="id">The id.</param> 
     /// <returns></returns> 
     Article Article(int id); 
    } 
} 

그리고 여기에 인터페이스가 두 개로 나뉘어져 있습니다. 첫 번째 인터페이스는 ... 교육부, Ministryweb 클래스 라이브러리에 정의되어

namespace Ministry.Ministryweb.Repositories 
{ 
    public interface IMinistrywebPublishedContentRepository : IPublishedContentRepository 
    { 
     /// <summary> 
     /// Gets the blog roll. 
     /// </summary> 
     IBlogRoll BlogRoll { get; } 

     /// <summary> 
     /// Gets the root ancestor. 
     /// </summary> 
     IPublishedContent RootAncestor { get; } 

     /// <summary> 
     /// Gets the consultancy URL. 
     /// </summary> 
     string ConsultancyUrl { get; } 

     /// <summary> 
     /// Gets the development URL. 
     /// </summary> 
     string DevelopmentUrl { get; } 

     /// <summary> 
     /// Gets the team management URL. 
     /// </summary> 
     string TeamManagementUrl { get; } 

     /// <summary> 
     /// Gets the name of the root ancestor. 
     /// </summary> 
     string RootAncestorName { get; } 

     /// <summary> 
     /// Gets an article with the specified ID. 
     /// </summary> 
     /// <param name="id">The id.</param> 
     /// <returns></returns> 
     Article Article(int id); 
    } 
} 

이 Umbraco.Pylon, 나의 새로운 라이브러리의 부모 인터페이스에서 이제 상속 ...

namespace Umbraco.Pylon 
{ 
    /// <summary> 
    /// An interface for accessing published content. 
    /// </summary> 
    public interface IPublishedContentRepository 
    { 
     /// <summary> 
     /// Gets the media item. 
     /// </summary> 
     /// <param name="id">The id of the item.</param> 
     /// <returns></returns> 
     IPublishedContent MediaItem(int id); 

     /// <summary> 
     /// Gets the umbraco helper. 
     /// </summary> 
     UmbracoHelper Umbraco { get; } 

     /// <summary> 
     /// Determines if a piece of media exists. 
     /// </summary> 
     /// <param name="mediaId">The media id.</param> 
     /// <returns></returns> 
     bool MediaExists(int? mediaId); 

     /// <summary> 
     /// Gets the URL for some media content. 
     /// </summary> 
     /// <param name="mediaId">The media id.</param> 
     /// <returns>A nicely formed Url.</returns> 
     string MediaUrl(int? mediaId); 

     /// <summary> 
     /// Gets the content URL. 
     /// </summary> 
     /// <param name="nodeId">The node id.</param> 
     /// <returns>A nicely formed Url.</returns> 
     string ContentUrl(int nodeId); 

     /// <summary> 
     /// Returns the content at a specific node. 
     /// </summary> 
     /// <param name="id">The node id.</param> 
     /// <returns>Dynamic content.</returns> 
     dynamic Content(int? id); 
    } 
} 

내 주요 웹 프로젝트는 두 도서관에 대한 언급으로 사역 웹이라는 세 번째 프로젝트입니다. Ministry.Ministryweb에는 또한 Umbraco.Pylon에 대한 언급이 있습니다. 나는이보기를로드 할 때이 설정의 모든 것을

@inherits MinistrywebViewPage 
@{ 
    Layout = "_Layout.cshtml"; 
    ViewBag.Title = DynamicModel.Name + " - " + Ministryweb.Content.RootAncestorName; 
} 
@section PageTitle 
{ 
    @DynamicModel.PrimaryHeader 
} 
<section id="primary"> 
    @if (Ministryweb.Content.MediaExists(DynamicModel.MainImage)) 
    { 
     <div class="serviceImage"> 
      <img src="@Ministryweb.Content.MediaUrl(DynamicModel.MainImage)" alt="@DynamicModel.Name" /> 
     </div> 
    } 
    @DynamicModel.IntroText 
    @foreach (var service in DynamicModel.Children) 
    { 
     <h3><a href="@service.NiceUrl()">@service.Name</a></h3> 
     <p>@service.Summary</p> 
     <span class="linkButton"><a href="@service.NiceUrl()">@service.TagLine</a></span> 
     <br /> 
    } 
    <div class="clearfix"></div> 
</section> 
<section id="asideContainer"> 
    @Html.Partial("_SocialSidebar") 
    @Html.Partial("_LogosSidebar") 
</section> 
<section id="articles"> 
    @Html.Partial("_LatestArticleForAll") 
</section> 

나는 다음과 같은 오류되게하고 ...

'Ministry.Ministryweb.Repositories.IMinistrywebPublishedContentRepository'가 포함되어 있지 않습니다 ... 잘 컴파일하지만, 'MediaExists'에 대한 정의

이것은 내게 전혀 의미가 없습니다.

처음에는 Ministryweb 웹 프로젝트에서 Umbraco.Pylon에 대한 직접적인 언급이 없었기 때문에 다른 게시물에 대한 제안에 따라 명시 적으로 포함 시켰지만 아무런 차이가 없었습니다.

미친 짓은 내가 IMinistrywbPublishedContentRepository 인터페이스의 IPublishedContentRepository 인터페이스에서 코드를 복제하면 모든 것이 제대로 작동한다는 것입니다. ReSharper는 저에게 신음합니다. 이 문제를 일으킬 수있는 것에 대한 생각은 내 리팩터링 작업이 중단됨에 따라 가장 환영받을 것입니다.

+0

완전히 청소하고 재구성 해 보셨습니까? –

+0

나는 재건을 시도했으나, 나는 편집증이 깨끗한 루틴을 다시 거쳐야한다고 생각한다. 이제 레퍼런스를 변경하고 그것이 도움이되는지 확인한다. –

+0

새 버전과 충돌하는 어딘가에 남겨진'IMinistrywebPublishedContentRepository'의 중복 된 정의가 없는지 확인하고 싶습니다. –

답변

0

OK - 이것은 최종 답변보다 더 많은 해결 방법이므로 더 이상 표시하지 않을 것입니다. 앞으로이 문제를 찾는 모든 사용자에게 해당 될 수 있습니다.

이 문제는보기를 통해 인터페이스의 속성에 액세스하려고 할 때만 발생합니다. 나는 여러 객체에 전달 된 매개 변수로서 내 코드베이스 전체에서 동일한 인터페이스를 사용하며 완벽하게 작동합니다. 이것은 조금 이상합니다 (그리고 나는 아직도 왜 그런지 정말로 알고 싶습니다).

보기는

namespace Ministry.Ministryweb 
{ 
    /// <summary> 
    /// Elements for the site. 
    /// </summary> 
    public class Ministryweb 
    { 
     private static IContainer container; 

     #region | Construction | 

     /// <summary> 
     /// Initializes a new instance of the <see cref="Ministryweb" /> class. 
     /// </summary> 
     /// <param name="umbracoHelper">The umbraco helper instance.</param> 
     public Ministryweb(UmbracoHelper umbracoHelper) 
     { 
      Content = new MinistrywebPublishedContentRepository(umbracoHelper); 
     } 

     #endregion 

     public IMinistrywebPublishedContentRepository Content { get; private set; } 
    } 
} 

... 뷰 콘텐츠 요소를 노출 단순히 존재이 클래스를 통해 자신이 클래스의 인스턴스를 얻을이베이스 클래스로부터 상속되는보기 인터페이스 액세스 ..

/// <summary> 
/// An abstract base class for Ministryweb views. 
/// </summary> 
public abstract class MinistrywebViewPage : UmbracoTemplatePage 
{ 
    private Ministryweb ministryweb; 

    /// <summary> 
    /// Gets the model in a dynamic form. 
    /// </summary> 
    public dynamic DynamicModel { get { return CurrentPage; } } 

    /// <summary> 
    /// Entry point for helper functions defined at root site level. 
    /// </summary> 
    /// <value> 
    /// The ministryweb helper object. 
    /// </value> 
    public Ministryweb Ministryweb 
    { 
     get 
     { 
      ministryweb = ministryweb ?? new Ministryweb(Umbraco); 
      return ministryweb; 
     } 
    } 
} 

내 생각에는 단순히보기에 대한 접근 자이므로 Content 속성을 인터페이스로 정의 할 이유가 전혀 없습니다. 대신 이걸하면 ...

... 모든 것이 잘 작동합니다.

사람들에게 도움이되기를 바랍니다.

관련 문제