Skip to content

Latest commit

 

History

History
99 lines (76 loc) · 3.26 KB

README.md

File metadata and controls

99 lines (76 loc) · 3.26 KB

Snickler.RSSCore: ASPNETCore Middleware for generating RSS Feeds

NuGet

This library was created in order to provide a way to easily generate RSS feeds on the fly via an ASP.NET Core Middleware.

Targets

Currently supports:

  • ASPNET Core 1.1 (netstandard1.3)
  • ASPNET Core 2.x (netstandard2.0)

Getting Started

Add the NuGet package to your project(s). Utilize the namespaces: Snickler.RSSCore.Models, Snickler.RSSCore.Providers, and Snickler.RSSCore.Extensions.

Create an RSS Provider

Create a provider class that implements IRSSProvider and returns a list of RSSItem objects via the RetrieveSyndicationItems method.

public class SomeRSSProvider: IRSSProvider
{
    public Task<IList<RSSItem>> RetrieveSyndicationItems()
    {
        IList<RSSItem> syndicationList = new List<RSSItem>();
        var synd1 = new RSSItem("Sample Title 1", "Sample Content 1")
        {
            PermaLink = new Uri("http://www.sampleaddress.com/sample-content-1"),
            LinkUri = new Uri("http://www.sampleaddress.com/sample-content-1"),
            LastUpdated = DateTime.Now,
            PublishDate = DateTime.Now,
            Categories = new List<string> { ".NET" },
            Authors = new List<string> { "someuser@sampleaddress.com" }
        };

        syndicationList.Add(synd1);

        return Task.FromResult(syndicationList);
    }
}

RSS Feed Configuration

Add your provider to the service registration in ConfigureServices with the AddRSSFeed extension

	public void ConfigureServices(IServiceCollection services)
	{
		services.AddRSSFeed<SomeRSSProvider>();
		services.AddMvc();
	}

Set the options for your RSS Feed in Configure with UseRSSFeed

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseRssFeed("/feed", new RSSFeedOptions
        {
            Title = "Snickler's Super Awesome RSS Feed",
            Copyright = "2018",
            Description = "The Best and Most Awesome RSS Feed Content",
            ManagingEditor = "managingeditor@someaddress.com",
            Webmaster = "webmaster@someaddress.com",
            Url = new Uri("http://someaddress.com")
        });
    }

Optional RSS Caching Configuration

By default, MemoryCache is used to cache the feed for 1 day. To be able to update the cache duration or cache key, add a new instance of the MemoryCacheProvider to the Caching property within the RSSFeedOptions class.

    app.UseRssFeed("/feed", new RSSFeedOptions
    {
        Title = "Snickler's Super Awesome RSS Feed",
        Copyright = "2018",
        Description = "The Best and Most Awesome RSS Feed Content",
        ManagingEditor = "managingeditor@someaddress.com",
        Webmaster = "webmaster@someaddress.com",
        Url = new Uri("http://someaddress.com"),
        Caching = new MemoryCacheProvider 
        {
            CacheDuration = TimeSpan.FromDays(5),
            CacheKey = "SomeSuperAwesomeCacheKey"
        }
    });

With this example setup, you'll be able to access the feed at http://whateverurl.com/feed

Example Project

An example project is located within the .sln file in the source.