1

我已经构建了一个 Silverlight 4 应用程序,但遇到了问题。

我已将我的应用程序拆分为多个 xap(不同的子系统)以减少下载/提高性能,因为并非每个用户都需要所有子系统。

但是,我想在 xap 之间共享 WebContext,而不是再次进行身份验证并为每个 xap 设置 WebContext。

这可能吗?如果是这样,我该如何实现?

4

1 回答 1

1

您需要与所有应用程序共享一个库。因此,假设您有 3 个 XAP 项目,分别称为 Project1.xap、Project2.xap 和 Project3.xap。所有这些项目都应该引用另一个具有共享逻辑的 silverlight 类库。在这个共享项目中,您可以创建一个由根应用程序实现的接口。我们称之为 IApplicationContext。

根应用程序是加载所有其他 XAP 的 XAP 文件。我们称它为 Root.xap。这个将管理身份验证并创建 IApplicationContext 的实现,它将在创建时传递给其他 XAP。

// This is available for all projects (shared.dll)
public interface IApplicationContext
{
    string Username { get; }
    Guid SessionId { get; }
    // ...
}

// This is implemented in the root application (Root.xap)
public class MyAppContext : IApplicationContext
{
    public string Username { get; private set; }
    public Guid SessionId { get; private set; }
    // ...
}

您可以在应用程序之间共享任何内容,这将使您的单独项目保持可测试性,因为您始终可以存根/模拟 IApplicationContext。

于 2011-04-28T23:48:37.780 回答