C# BlackBerry(tm) Push Service SDK

SDK Bootstrapping

Introduction
The Push Service SDK makes use of the Enterprise Library v5 and Unity.
To ensure that these dependencies are initialised correctly along with the SDK itself requires the use of a bootstrap class.

The following code is taken from the example web-site and illustrates how to initialise the SDK and the Enterprise Library.

Initialise the container

The first step is to setup the Unity IoC container…

protected virtual IUnityContainer CreateContainer()
{
    return EnterpriseLibraryContainer.Current.GetInstance<IUnityContainer>();
}

As you can see instead of creating a new UnityContainer instance the default container from the Enterprise Library is used instead.

Configure low-level services

Next up is the initialisation of all the SDK low-level services.

/// <summary>
/// Configures the low-level Push API services.
/// </summary>
/// <remarks>
/// Registers the following services:
/// IIdGenerator, IBoundaryGenerator, IPapService
/// </remarks>
protected virtual void ConfigureLowLevelServices()
{
    // Setup Push Properties
    if (!Container.IsRegistered<IPushProperties>())
    {
        Container.RegisterType<IPushProperties, PushProperties>(
            new ContainerControlledLifetimeManager());
    }

    // Setup Push ID generator passing in domain name
    if (!Container.IsRegistered<IIdGenerator>())
    {
        Container.RegisterType<IIdGenerator, IdGenerator>(
            new ContainerControlledLifetimeManager(),
            new InjectionConstructor(PushIdDomainName));
    }

    // Setup Boundary generator
    if (!Container.IsRegistered<IBoundaryGenerator>())
    {
        Container.RegisterType<IBoundaryGenerator, BoundaryGenerator>(
            new ContainerControlledLifetimeManager());
    }

    // Setup Pap service if not already registered
    if (!Container.IsRegistered<IPapService>())
    {
        if (!UseAcknowledgements)
        {
            Container.RegisterType<IPapService, PapService>(
                new ContainerControlledLifetimeManager());
        }
        else
        {
            Container.RegisterType<IPapService, AcknowledgementPapService>(
                new ContainerControlledLifetimeManager());
        }
    }
}

Pretty striaghtforward and as you can see there are no repository registrations here – note however that if you wish to use acknowledgements then this will be dependent on higher-level services and thus require database support. The class is registered in this method because it is a replacement IPapService.

Configure high-level services

Next step is to setup high-level services and repositories.

/// <summary>
/// Configures the high-level Push API services.
/// </summary>
protected virtual void ConfigureHighLevelServices()
{
    // Setup high-level services
    Container.RegisterType<IPushApplicationService, PushApplicationService>(
        new ContainerControlledLifetimeManager());
    Container.RegisterType<IPushCountService, PushCountService>(
        new ContainerControlledLifetimeManager());
    Container.RegisterType<IPushRequestService, PushRequestService>(
        new ContainerControlledLifetimeManager());
    Container.RegisterType<IPushRequestDetailService, PushRequestDetailService>(
        new ContainerControlledLifetimeManager());
    Container.RegisterType<IPushStatsService, PushStatsService>(
        new ContainerControlledLifetimeManager());
    Container.RegisterType<IPushStatsBatchUpdaterService, PushStatsBatchUpdaterService>(
        new ContainerControlledLifetimeManager());
    Container.RegisterType<ISubscriptionService, SubscriptionService>(
        new ContainerControlledLifetimeManager());
    Container.RegisterType<IPushService, PushService>(
        new ContainerControlledLifetimeManager());

    // Content-provider interfaces are next
    ConfigureContentProviderServices();

    if (!Container.IsRegistered<IContentProviderSubscriptionService>())
    {
        Container.RegisterType<IContentProviderSubscriptionService, ContentProviderSubscriptionService>(
            new ContainerControlledLifetimeManager());
    }
    if (!Container.IsRegistered<IContentProviderAuthenticationService>())
    {
        Container.RegisterType<IContentProviderAuthenticationService, ContentProviderAuthenticationService>(
            new ContainerControlledLifetimeManager());
    }
}

Much the same as the low-level registrations however it is assumed that the high-level APIs will not be overridden by client applications.

The call to ConfigureContentProviderServices gives derived classes a chance to register implementations of the content-provider services before the code will attempt to register stub versions.

Default Content Provider Services

The default IContentProviderSubscriptionService simply contains empty methods.

The default IContentProviderAuthenticationService delegates authentication logic to ASP.NET Membership and Role classes making it easy to get up and running.

Get the latest source

Download the latest source (from the source code tab) and take a look at the sample web-site and the WebBootstrapper.cs file for the complete implementation of the bootstrap object.

Last edited Jun 20, 2012 at 4:02 PM by dementeddevil, version 4

Comments

No comments yet.