开发者

Silverlight4 WebContext

开发者 https://www.devze.com 2023-03-01 23:36 出处:网络
I have built a Silverlight 4 application and I have hit a problem. I have split my application into multiple xaps(different sub-systems) to reduce downloading / improve performance as not all subsyst

I have built a Silverlight 4 application and I have hit a problem.

I have split my application into multiple xaps(different sub-systems) to reduce downloading / improve performance as not all subsystems are needed by every user.

However I want to share the WebContext between the xaps, rather than authenticating again and setting WebContext for each xap.

Is this possible? I开发者_Go百科f so how can I achieve it?


You need to share a library with all your applications. So, let's assume you have 3 XAP projects called Project1.xap, Project2.xap, and Project3.xap. All these projects should reference another silverlight class library that has shared logic. In this shared project, you can create an interface that's implemented by the root application. Let's call this IApplicationContext.

The root application is the XAP file that loads all the other XAPs. Let's call it Root.xap. This one will manage the authentication and create an implementation of IApplicationContext which it will pass to the other XAPs upon creation.

// 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; }
    // ...
}

You can share anything between the applications, and it will keep your separate projects testable because you can always stub/mock the IApplicationContext.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号