SwEx.AddIn frameworks provides utility class to manage document life cycle by creating a specified instance handler as a wrapper of a model.

Define the document handler either by implementing the IDocumentHandler interface or DocumentHandler class. Later one handles some commonly used events which can be overridden, such as document activation, loading and storing from 3rd party storage and store.

public class MyDocHandler : DocumentHandler
{
    public override void OnInit()
    {
        //TODO: init
    }

    public override void OnDestroy()
    {
        //TODO: release
    }
}

Call ISwAddInEx.CreateDocumentsHandler method and pass the type of document handler as a generic argument

private IDocumentsHandler<MyDocHandler> m_DocHandler;
...
m_DocHandler = CreateDocumentsHandler<MyDocHandler>();
...

Override methods of document handler and implement required functionality attached for each specific SOLIDWORKS model (such as handle events, load, write data etc.)