Jason Durrant
Jason Durrant

Reputation: 21

RavenDB Error: I can't access var store from a different class. Any Suggestions

RavenDB Error: var store isn't a global variable. How do I create a class that can use access documentstore? Any comments on why this code refuses to run is greatly appreciated

    class Program
    { 
        static void Main(string[] args)
        {
            var store = new DocumentStore
            {
                Urls = new[] { "http://localhost:8080" },
                Database = "Tasks"
            };

            store.Initialize();

        }
     class OtherProgram

        using (var session = Store.OpenSession())
                    {
                        var task = session.Load<Entity>(combinedInitial + email)
//More code
}


    

Upvotes: 2

Views: 52

Answers (1)

Danielle
Danielle

Reputation: 3839

Usually, you would use a single document-store instance per application (singleton).

See the common pattern for initializing the DocumetnStore here:
https://ravendb.net/learn/inside-ravendb-book/reader/4.0/2-zero-to-ravendb#the-document-store

See walkthrough and explanations in this demo:
https://demo.ravendb.net/demos/csharp/basics/the-document-store

Can also follow the example in the Bootcamp repository
https://github.com/ravendb/bootcamp/tree/v5.x/src/unit1/lesson4#exercise-moving-the-documentstore-instance-to-a-singleton-class

Upvotes: 2

Related Questions