Caliburn 부트 스트 래퍼에서 사용자가 내 응용 프로그램을 실행할 수있는 권한이 있는지 확인하려고합니다. 그렇지 않으면 메시지를 발표하고 종료해야합니다. 다음 코드는 MessageBox.Show() 호출에서 NullReferenceException을 발생시킵니다. ComposeMef()
호출을 Configure()
메서드의 ValidateUserHasPermissionsToRun()
전에 이동해도 오류가 발생합니다.Caliburn 부트 스트 래퍼에 MessageBox 표시 구성()
public class MyBootstrapper : Bootstrapper<DropWindowViewModel>
{
// irrelevant methods omitted for brevity
protected override void Configure()
{
this.InitializeSecurity();
this.ValidateUserHasPermissionToRun();
this.ComposeMef();
}
private void ComposeMef()
{
AggregateCatalog catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>());
this.container = new CompositionContainer(catalog);
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(this.container);
batch.AddExportedValue(catalog);
this.container.Compose(batch);
}
private void ValidateUserHasPermissionToRun()
{
User user = SecurityContext.Current.SecurityUser;
if (!user.HasPrivilege(Constants.PrivilegeLoadData))
{
// throws an exception
MessageBox.Show("You do not have access to VIPER. Please contact the help desk if you need help.");
this.TerminateApplication();
}
}
}
이 문제를 해결하는 적절한 방법은 무엇입니까? 이 간단한 내용을 보려면 메시지 상자를 보여주고 싶습니다. 완전히 새로운 ViewModel/View를 작성하고 싶지는 않습니다. 다른 ViewModel을 사용해야하는 경우 ViewModel Caliburn이 사용하는 전환 방법은 무엇입니까? 또는 다른 인터페이스를 트리거하기 위해 DropWindowViewModel
에 속성을 설정해야합니까?
나는 그것을 살 수있다. 좋은 대답. – michaelkoss