anchor.diff:                                                                      writer |> IndexWriter.deleteDocument id }
       
       /// Delete all documents of an index
  -    let deleteAllDocument (indexName) (state : State.T) = maybe { let! writer = state.IndexFactory 
  -                                                                                |> LazyFactory.getInstance indexName
  -                                                                  writer |> IndexWriter.deleteAllDocuments }
  +    let deleteAllDocuments (indexName) (state : State.T) = maybe { let! writer = state.IndexFactory 
  +                                                                                 |> LazyFactory.getInstance indexName
  +                                                                   writer |> IndexWriter.deleteAllDocuments }
  +    
  +    type Service(searchService : ISearchService, state : State.T) = 
  +        interface IDocumentService with
  +            member __.GetDocument(indexName, documentId) = searchService |> getDocument indexName documentId
  +            member __.GetDocuments(indexName, count) = searchService |> getDocuments indexName count
  +            member __.AddOrUpdateDocument(document) = state |> addOrUpdateDocument document
  +            member __.AddDocument(document) = state |> addDocument document
  +            member __.DeleteDocument(indexName, documentId) = state |> deleteDocument indexName documentId
  +            member __.DeleteAllDocuments indexName = state |> deleteAllDocuments indexName
  
positive.code: /// Document related operations
  type IDocumentService = 
      abstract GetDocument : indexName:string * id:string -> Choice<Document.Dto, Error>
      abstract GetDocuments : indexName:string * count:int -> Choice<Document.Dto, Error>
      abstract AddOrUpdateDocument : document:Document.Dto -> Choice<unit, Error>
      abstract DeleteDocument : indexName:string * id:string -> Choice<unit, Error>
      abstract AddDocument : document:Document.Dto -> Choice<CreateResponse, Error>
  
negative.code:     
      /// Check if a given index exists
      let indexExists (indexName) (state : T) = state.IndexFactory |> LazyFactory.exists indexName indexNotFound
      
      /// Checks if a given index exists and returns the state of the index if it exists
      let indexExists2 (indexName) (state : T) = 
          match state.IndexFactory |> LazyFactory.getState indexName with
          | Choice1Of2(state) -> ok <| state
          | Choice2Of2(_) -> fail <| IndexNotFound indexName
      
      /// Checks if a given index is online or not. If it is online then return the index writer    
      let indexOnline (indexName) (state : T) = 
          match state |> indexExists2 indexName with
          | Choice1Of2(indexState) -> 
              if indexState = IndexState.OnlineMaster then ok <| (state.IndexFactory.ObjectStore.[indexName].Value.Value)
              else fail <| IndexShouldBeOnline(indexName)
          | Choice2Of2(error) -> fail <| error
  
  module IndexService = 
      /// Returns IndexNotFound error
  