DragonFly.Templates 0.9.17

There is a newer version of this package available.
See the version list below for details.
dotnet new install DragonFly.Templates::0.9.17
This package contains a .NET Template Package you can call from the shell/command line.

DragonFly - Headless CMS based on ASP.NET Core and Blazor

License: MIT

Package Release
DragonFly.Core NuGet
DragonFly.AspNetCore NuGet
DragonFly.API NuGet
DragonFly.Client NuGet
DragonFly.BlockField NuGet
DragonFly.Proxy NuGet
DragonFly.ImageWizard NuGet
DragonFly.MongoDB NuGet
DragonFly.Identity NuGet
DragonFly.ApiKeys NuGet

Getting started

Prerequisites

Create a new project from template

To use the project template you need first to download and install it from NuGet.

dotnet new install DragonFly.Templates

After this you can create the project with:

dotnet new DragonFly

If you have a remote MongoDB instance, you need to add some appsettings:

"MongoDB": {
    "Hostname": "localhost",
    "Database": "DragonFly_App",
    "Port": 27017,
    "Username": "",
    "Password": ""
  },

DragonFly

grafik

Supported fields

  • StringField
  • FloatField
  • BoolField
  • AssetField
  • ReferenceField
  • ComponentField
  • ArrayField
  • DateField
  • IntegerField
  • ColorField
  • GeoLocationField
  • SlugField
  • XmlField
  • HtmlField
  • BlockField (HeadingBlock, TextBlock, HtmlBlock, CodeBlock, ContainerBlock, ColumnBlock, AssetBlock, ReferenceBlock, GridBlock,..)

How to create new content schema and content item

IContentStorage contentStorage = ...;//use MongoStorage or ClientContentService (http client)

//create brand schema
ContentSchema schemaBrand = new ContentSchema("Brand")
                                    .AddString("Name")
                                    .AddSlug("Slug")
                                    .AddTextArea("Description");

//Define schema for product
ContentSchema schemaProduct = new ContentSchema("Product")
                                    .AddReference("Brand")
                                    .AddString("Name", options => options.IsRequired = true)
                                    .AddSlug("Slug")
                                    .AddBool("IsAvailable", options => options.DefaultValue = true)
                                    .AddFloat("Price")
                                    .AddTextArea("Description", options => options.MaxLength = 255)
                                    .AddArray("Attributes", options => options
                                                                        .AddString("Name")
                                                                        .AddString("Value"));

await contentStorage.CreateAsync(schemaProduct);

//create product by schema
ContentItem contentProduct = schemaProduct
                            .CreateContent()
                            .SetReference("Brand", new ContentItem(Guid.Parse(""), schemaBrand))
                            .SetString("Name", "ProductA")
                            .SetBool("IsAvailable", true)
                            .SetFloat("Price", 9.99)
                            .SetTextArea("Description", "...")
                            .AddArrayItem("Attributes", schemaProduct, item => item
                                                                    .SetString("Name", "Size")
                                                                    .SetString("Value", "M"));

await contentStorage.CreateAsync(contentProduct);

Create typed content

[ContentItem("BlogPost")]
public class BlogPostModel : EntityPageModel
{
    [DateField(Required = true)]
    public virtual DateTime? Date { get; set; }

    [StringField(Required = true, Searchable = true, ListField = true, MinLength = 8, MaxLength = 512)]
    public virtual string Title { get; set; }

    [TextField]
    public virtual string Description { get; set; }

    [SlugField(Required = true, Index = true)]
    public virtual string Slug { get; set; }

    [AssetField(ListField = true, ShowPreview = true)]
    public virtual AssetField Image { get; set; }

    [BlockField]
    public virtual BlockField MainContent { get; set; }
}
Register typed content
builder.Services.AddDragonFly()
                    .AddProxy(x => x.AddType<BlogPostModel>());                    
Use queries for typed content
//get first item
var first = await ContentStorage.FirstOrDefaultAsync<BlogPostModel>(x => x
                                    .SlugQuery(x => x.Slug, slug));

//get all items
var result = await ContentStorage.QueryAsync<BlogPostModel>(x => x
                                    .Published(true)
                                    .Top(10)
                                    .SlugQuery(x => x.Slug, slug));

BackgroundTask

For long running jobs you can use the BackgroundTaskManager.

IBackgroundTaskManager taskManager = app.Services.GetRequiredService<IBackgroundTaskManager>();
taskManager.Start("Test", async ctx => await Task.Delay(TimeSpan.FromSeconds(60), ctx.CancellationToken));

DragonFly.AspNetCore

builder.Services.Configure<DragonFlyOptions>(Configuration.GetSection("General"));
builder.Services.Configure<MongoDbOptions>(Configuration.GetSection("MongoDB"));

//add DragonFly services
builder.Services.AddDragonFly()
                  .AddImageWizard()
                  .AddRestApi()
                  .AddMongoDbStorage()
                  .AddMongoDbIdentity()
                  .AddBlockField()
                  .AddApiKeys();

var app = builder.Build();

//init DragonFly
await app.InitDragonFlyAsync();

if (env.IsDevelopment())
{
  app.UseDeveloperExceptionPage();
  app.UseWebAssemblyDebugging();
}

app.UseDragonFly(x => x             
                  .MapImageWizard()
                  .MapApiKey()
                  .MapIdentity()
                  .MapRestApi());
app.UseDragonFlyManager();
app.UseRouting();
app.Run();

DragonFly.Client (Blazor)

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<DragonFly.App.Client.App>("app");

//Register DragonFly components
builder.AddDragonFly()
          .AddRestApi()
          .AddBlockField()
          .AddIdentity()
          .AddApiKeys();

WebAssemblyHost host = builder.Build();

await host.InitDragonFlyAsync();
await host.RunAsync();
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.15 96 4/27/2024
1.0.14 87 4/27/2024
1.0.12 219 3/19/2024
1.0.10 158 3/19/2024
1.0.8 425 3/8/2024
1.0.7 200 3/3/2024
1.0.6 378 2/22/2024
1.0.5 511 2/7/2024
1.0.4 638 1/19/2024
1.0.3 355 1/10/2024
1.0.2 1,153 12/3/2023
1.0.1 184 12/2/2023
1.0.0 179 11/30/2023
0.9.31 416 7/27/2023
0.9.22 184 6/30/2023
0.9.17 177 5/9/2023
0.9.16 157 4/28/2023
0.9.15 159 4/27/2023
0.9.11 299 3/19/2023
0.9.10 253 3/8/2023
0.9.9 206 3/3/2023
0.9.8 334 1/29/2023
0.9.7 294 1/27/2023
0.9.6 298 1/27/2023
0.9.5 314 1/25/2023
0.9.3 319 1/4/2023
0.9.2 334 1/3/2023
0.9.1 344 12/28/2022
0.9.0 299 12/28/2022
0.8.4 327 12/19/2022
0.8.3 267 12/18/2022
0.8.2 268 12/18/2022
0.8.1 324 12/18/2022
0.8.0 307 12/18/2022