Answered

AgilityContentRepository Use in Console Applications / WebJob

Hey Agility <gang signs>

Is it possible to use the AgilityContentRepository object in a console application or a WebJob.

I'm currently trying to do so and I'm running into an issue where when I attempt to request data via from a repo thats been created and instantiated, but I'm consistently getting a null reference. Unfortunately I'm uncertain if a connection is being created, and the object that I'm creating is just running off the default values.

 

for example I've the following: 

public static Awesome GetAwesome()
{
    Awesome item = default(Awesome);

    var repo = CreateRepository<Awesome>("Awesome", "en-ca");

    if (repo != null)
    {
item = repo.Item(string.Empty);
    }

    return item;
}

private static IAgilityContentRepository<TRepository> CreateRepository<TRepository>(
    string referenceName,

    string languageCode) where TRepository : AgilityContentItem
{
    IAgilityContentRepository<TRepository> repository = default(IAgilityContentRepository<TRepository>);

    try
    {
repository = new AgilityContentRepository<TRepository>(referenceName, languageCode);
    }

    catch (Exception)
    {
repository = default(IAgilityContentRepository<TRepository>);
    }

    return repository;
}

if I try and use the GetAwesome() function it throws an exception on item.repo.Item(string.Empty) and I'm unsure as to why. Using this in and mvc application there are no issues. When I use this in my console application if I've never used this method, or I've deleted my temp files this works, but never again after that.

Mike

0

Comments

2 comments
  • Official comment

    Ya I don't think you can do this using a console app, I believe there are dependencies on System.Web.Mvc. As per Joel's comments, you'll need to use the Content Import API for this for the time being.

    We are working on a high-availability REST API which will be much better for this. More details on this will be released in the coming months.

    Comment actions Permalink
  • Hi Mike - you need to make sure that the app has a properly initialized configuration file, pointing to a previously synced content files folder.  You could also use the Content Import API to do this.  The main difference is that by using the AgilityContentRepository, you need to have a content files folder.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post