2011-11-07 2 views
0

프리즘 애플리케이션에서 사용자가 트리의 항목 (별도 모듈)을 클릭하면 가운데 패널에 모듈을로드해야합니다. 가운데 창에있는 모듈 (디자이너 모듈을 말함)은 파일을 열고 경로가 주어진 경우 자체를 표시 할 수 있습니다. 파일의 경로를이 모듈에 전달하려면 어떻게해야합니까? 디자이너 모듈프리즘으로 동기화 된 메시지 전달

public DesignerViewModel(DataAccess dataAccess)// This will be injected 
{ 
} 


//The following class can create the model objects using the IDataService for getting data from remote location 
public DataAccess(IDataService service)//this will be injected 
{ 
} 

데이터 액세스 개체 디자이너 모듈에 국부적이므로, I는 모듈 외부에 노출하고자 wouldnt하는 예

들어 . 그래서 등록이

public class DesignerModule : IModule 
{ 
     public void Initialize() 
     { 
      var container = ServiceLocator.Current.GetInstance<IUnityContainer>(); 
      container.RegisterType<Object, DesignerView>("DesignerUI"); 
      container.RegisterType<DataAccess>();    
     } 
    } 

IDataService는 응용 프로그램 수준 IDataService 전체 앱의 싱글 것을

public class BootStrapper : UnityBootstrapper 
    { 
     protected override void ConfigureContainer() 
     { 
      base.ConfigureContainer(); 
      Container.RegisterType<IDataService, DataService>(); 
     } 
    } 

주에 등록 된 모듈에서 수행됩니다. IDataService에서 모듈 인스턴스와 관련된 파일 경로를 전달할 수 없습니다. 중앙 창의 원하는 개수만큼 모듈을 열 수 있습니다. 트리 항목 -> 트리를 클릭하면 선택된 항목으로 이벤트가 실행됩니다. id-> app은 항목 ID에 해당하는 경로를 찾고 호출합니다. 모듈.

_regionManager.AddToRegion ("CenterRegion", DesignerModule);을 말할 때 어떻게 경로를 전달합니까? Prism은 모든 의존성 주입을 아름답게 할 것입니다. 그러나 경로를 전달하는 방법은 큰 문제입니다.

답변

0

난 당신이 해결을 호출 할 때 자신의 객체를 오버라이드 (override) 할 수 있습니다 내 colleague.The 매개 변수에서 답을 발견(). 그래서 주입 될 객체를 만들고 그것을 채우고 ParameterOverride를 사용하여 Resolve <>()을 전달하십시오. 자세한 내용은 Google의 ParameterOverride를 검색하십시오.

0

EventAggregator을 사용하면 다른 모듈과 메시지를 교환 할 수 있습니다. 각 모듈은 EventAggregator에 가입합니다. 모듈을 여는 동안 신생아에 대한 호스트 제어 알림으로 보낼 수 있습니다. 호스트 제어가 초기화 데이터와 함께 응답을 보냅니다.

public class MessageEvent : CompositePresentationEvent<Message>{} 

internal class MessageReceiver 
{ 
    private readonly MessageEvent _evt; 
    private readonly string _myId = Guid.NewGuid().ToString(); 

    internal MessageReceiver(IEventAggregator eventAggregator) 
    { 
     _evt = eventAggregator.GetEvent<MessageEvent>(); 
     _evt.Subscribe(Receive, true); 

     _evt.Publish(new Message { Source = _myId, Command = Message.Commands.WhoIAm }); 
    } 
    public void Receive(Message message) 
    { 
     switch (message.Command) 
     { 
      case Message.Commands.WhoIAm: 
       _evt.Publish(
        new Message 
        { 
         Destination = message.Source, 
         Command = Message.Commands.Initialize, 
         MessageData = Encoding.UTF8.GetBytes("init data") 
        }); 
       break; 
      case Message.Commands.Initialize: 
       if (message.Destination == _myId) 
       { 
        //init 
       } 
       break; 
     } 
    } 
} 
public class Message 
{ 
    public enum Commands { Initialize, WhoIAm } 

    public string Source { get; set; } 
    public string Destination { get; set; } 
    public Commands Command { get; set; } 
    public byte[] MessageData { get; set; } 
} 
+0

@ Radik- 이것은 내가 원하는 것만은 아닙니다. 모듈 생성 자체는 경로 정보를 포함하는 트리 모듈의 이벤트 때문입니다. 이 이벤트는 메인 애플리케이션에 의해 처리되고 mainapp는 애플리케이션의 가운데 창에 디자이너 모듈을 생성합니다. 모듈 인스턴스 생성 시점에서 경로 정보를 전달하는 것이 좋습니다. – Jimmy