-1

I am trying to build a cache class using the Ardalis Example http://ardalis.com/introducing-the-cachedrepository-pattern

I am getting the error saying it has zero arguments. I can figure out how to pass the top part.

The cache part of the class has no errors and the base class works

What am i doing wrong in the top part of the respository class. How am i inheriting wrong.

Thank you for any help.

Repository Class with the problem

   public class TweetSearchCache : TweetSearch  
  {
   // SingleUserAuthorizer auth;

    public TweetSearchCache() : base //(SingleUserAuthorizer auth) 
    {



    }

    private static readonly object CacheLockObject = new object();
    public override List<Search>  GetTweets()
   {

        string cacheKey = "GetSearch";



        var result = HttpRuntime.Cache[cacheKey] as List<Search>;

        if (result == null)
        {
            lock (CacheLockObject)
            {
                result = HttpRuntime.Cache[cacheKey] as List<Search>;

                if (result == null)
                {

                    result = base.GetTweets().ToList();                                            

                    HttpRuntime.Cache.Insert(cacheKey, result, null,

                  DateTime.Now.AddMinutes(2), TimeSpan.Zero);

                }

            }
        }


        return result;



    }

  }

Base Class

    public class TweetSearch
    {
     private readonly SingleUserAuthorizer _auth;

      public TweetSearch(SingleUserAuthorizer auth)
    {
        _auth = auth;
    }


    public virtual List<Search> GetTweets()
    {
        string hashTerm = "#searchterm";

        string rejectedWords = "Searchterm";


        using (var twitterCtx = new TwitterContext(_auth))
        {
            var queryResults = (from search in twitterCtx.Search
                                where search.Type == SearchType.Search &&
                                      search.Hashtag == hashTerm ||
                                    //   search.Query == twitQuery ||
                                    //   search.WordPhrase == twitPhrase ||
                                      search.WordNot == rejectedWords &&

                                      search.ShowUser == true &&
                                      search.IncludeEntities == true &&
                                      search.Locale == "EN" &&
                                       search.PageSize == 100
                                select search).ToList();

            return queryResults;//.ToList();
        }



    }
Michael Hahn
  • 143
  • 1
  • 5
  • 12

1 Answers1

1

You should probably read more about basic C# syntax. The argument can either come from an argument in the derived constructor, or you can build it using a static field, property or method. The first example shows the base argument coming from the derived constructor. The second example shows the use of a static method.

public TweetSearchCache(SingleUserAuthorizer auth) : base(auth) {
// ...
}

Or

public TweetSearchCache() : base(CreateAuth()) {
// ...
}

public static SingleUserAuthorizer CreateAuth() {
    SingleUserAuthorizer createdAuth = ...
    // ...
    return createdAuth;
}
siride
  • 200,666
  • 4
  • 41
  • 62
  • Thank you the first one worked. I had the rest of my class working too. Thanks for helping me and showing me for the future, i didnt know i had to pass the single auth class again too – Michael Hahn Mar 27 '12 at 02:30