2
在我的Caliburn Bootstrapper中,我试图验证用户是否有权运行我的应用程序。如果他们不这样做,我需要给他们留言并退出。以下代码在MessageBox.Show()调用中抛出NullReferenceException。即使我在ValidateUserHasPermissionsToRun()
Configure()
方法之前调用ComposeMef()
,它仍然有错误。在Caliburn Bootstrapper中显示消息框Configure()
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 2012-08-22 13:32:52