We have already introduced you to our solution for a digital signature for SharePoint documents. In this article, we would like to explain to you in more detail how we have adapted our application to be able to use our solution for the digital signature in SharePoint Online.

SharePoint Online signature: Start workflow

Signature in SharePoint Online - Creation of a "Core" project

So that you can also install our solution for the digital signature in SharePoint Online, we have divided our project into several projects. We now have a “core” project, which does not contain any specific SharePoint functionalities. In this project, we map the basic functionality of our application only by means of interfaces. In the “Core” project, we therefore only work with the interfaces and not with concrete implementations.

SharePoint Online Unterschrift: Core Project

We have outsourced the implementations of these interfaces to different projects. Among other things we have created a Server Side Object Model (SSOM) project. This can be used, for example, in a SharePoint 2019 environment. For SharePoint Online, we have now added a Client Side Object Model (CSOM) project. Of course, you can add more projects here depending on your requirements. For example, it would also be possible to obtain the data not from SharePoint, but from a database.

Dependency Injection using Ninject

So that we can easily decide which project we want to use for the implementation, we load it using dependency injection. For this we use the Nuget package “Ninject”. Ninject works with so-called modules. These can be loaded into the project. In such a Ninject module you can define a class for a specific interface with the method “Bind”.

 public class SsomRepositoryModule : NinjectModule
{
    private readonly string _url;

    public SsomRepositoryModule(string url)
    {
        _url = url;
    }
    
    public override void Load()
    {
        Bind<IWorkflowRepository>().To<SsomWorkflowRepository>().WithConstructorArgument("url", _url);         
    }
}

This class is then instantiated when the interface is loaded.

WorkflowRepository = kernel.Get<IWorkflowRepository>();

We now have two Ninject modules – one for the SSOM project and one for the CSOM project.

We have added an interface for a module provider. This provider returns the correct Ninject module, which contains the correct bindings for the interfaces.

// Interface für den Module Provider
public interface IRepositoryModuleProvider
{
    NinjectModule GetRepositoryModule(string url);
}

// SSOM Implementierung des Module Providers
public NinjectModule GetRepositoryModule(string url)
{
    return new SsomRepositoryModule(url);
}

Separate projects for different SharePoint versions

The functionality of our “Core” project can now be used in the respective projects for different versions. For SharePoint Online, we created a Provider Hosted Add-in. In the page, when instantiating the PageInitializer, the required module providers are specified. The module provider returns the correct Ninject module, which contains the bindings of the interfaces. This gives you the correct implementations for the interfaces in the application. For SharePoint Online, we just specify a CSOMRepositoryModuleProvider here.

var contextUrl = HttpUtility.UrlDecode(Page.Request["SPHostUrl"]);

var pageInitializer = new PageInitializer<T, CsomRepositoryModuleProvider>(Page);
pageInitializer.Initialize(contextUrl);   // Im Initialize wird dann der Request verarbeitet und die weitere Funktionalität aufgerufen

So we can easily switch between the different implementations here. For this, we only need to customize a single line of code. If we want to use the SsomRepositoryModule, we simply specify the correct type when instantiating the PageInitializer. This automatically gives us the right SSOM implementations.

var pageInitializer = new PageInitializer<T, SsomRepositoryModuleProvider>(Page);

Have we aroused your interest and would you like more information about our solution for the digital signature for SharePoint Online? Then please get in touch with us.

Contact