OEmbed.Extensions.Microsoft.DependencyInjection
1.0.1
See the version list below for details.
dotnet add package OEmbed.Extensions.Microsoft.DependencyInjection --version 1.0.1
NuGet\Install-Package OEmbed.Extensions.Microsoft.DependencyInjection -Version 1.0.1
<PackageReference Include="OEmbed.Extensions.Microsoft.DependencyInjection" Version="1.0.1" />
paket add OEmbed.Extensions.Microsoft.DependencyInjection --version 1.0.1
#r "nuget: OEmbed.Extensions.Microsoft.DependencyInjection, 1.0.1"
// Install OEmbed.Extensions.Microsoft.DependencyInjection as a Cake Addin #addin nuget:?package=OEmbed.Extensions.Microsoft.DependencyInjection&version=1.0.1 // Install OEmbed.Extensions.Microsoft.DependencyInjection as a Cake Tool #tool nuget:?package=OEmbed.Extensions.Microsoft.DependencyInjection&version=1.0.1
OEmbed
A simple oEmbed consumer library for .NET
Install
via NuGet:
PM> Install-Package OEmbed
DI extensions for Microsoft.Extensions.DependencyInjection:
PM> Install-Package OEmbed.Extensions.Microsoft.DependencyInjection
DI configuration
services.AddOEmbed();
// or
services.AddOEmbed(options =>
{
options.EnableCache = true; // true by default
});
By default it's register all built in providers:
- InstagramProvider
- TiktokProvider
- TwitterProvider
- VimeoProvider
- YoutubeProvider
You can add a provider during configuration:
services.AddOEmbed()
.ClearProviders() // remove all default providers
.AddProvider<YoutubeProvider>()
.AddProvider<VimeoProvider>();
Usage
- Inject
IOEmbedConsumer
throught constructor injection. - Call one of RequestAsync() overloads.
For example:
using HeyRed.OEmbed.Abstractions;
using HeyRed.OEmbed.Models;
// Returns null if provider not found for given url
// NOTE: This method can throw HttpRequestException, so wrap your request with try/catch if it needed
Video? result = await _oEmbedConsumer.RequestAsync<Video>("https://vimeo.com/22439234");
The result object is are similar to described in the spec
Models: Base, Link, Photo, Rich, Video
If you dont know which response models supported by provider, then use dynamic overload.
// Deserialize response based on provider preferences
dynamic? item = await _oEmbedConsumer.RequestAsync(url);
if (item is not null)
{
if (item is Video)
{
// work with video
}
elseif (item is Photo)
{
// work with photo
}
else { //do something }
}
Caching
Configure cache options:
services.AddOEmbed().Configure<CacheOptions>(options =>
{
options.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(30); // Default is 1 hour
});
By default cache is enabled and it's default implementation is just a wrapper around MemoryCache
You can write your own implementation of ICache and replace default cache during app configuration:
services.AddOEmbed().SetCache<DistributedRedisCache>();
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- OEmbed (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.