The fastest way to get started is to use one of the Project Templates available. If you want to read more about this, please go to Project Templates.
All libraries and components are available on NuGet. You can read more about the available packages here.
If you want the latest source code and maybe be a part of the community and contribute to Piranha you should head over to GitHub. You can read more about this in Contribute.
In ConfigureServices
you should register the component services you want use in your application. As an example, let's look at the service configuration for a project that uses SQLite
and AspNetCore Identity
.
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options =>
options.ResourcesPath = "Resources"
);
services.AddMvc()
.AddPiranhaManagerOptions()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddPiranha();
services.AddPiranhaApplication();
services.AddPiranhaFileStorage();
services.AddPiranhaImageSharp();
services.AddPiranhaManager();
services.AddPiranhaEF(options =>
options.UseSqlite("Filename=./piranha.razorweb.db"));
services.AddPiranhaIdentityWithSeed<IdentitySQLiteDb>(options =>
options.UseSqlite("Filename=./piranha.razorweb.db"));
}
Once the services has been configured you need to initialize Piranha. Let's again look at how it's done in the example project. Please note that generic AspNetCore setup has been omitted.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApi api)
{
...
// Initialize Piranha
App.Init(api);
// Build page types
var pageTypeBuilder = new Piranha.AttributeBuilder.PageTypeBuilder(api)
.AddType(typeof(Models.StandardPage))
.AddType(typeof(Models.TeaserPage));
pageTypeBuilder.Build()
.DeleteOrphans();
// Register middleware
app.UseStaticFiles();
app.UseAuthentication();
app.UsePiranha();
app.UsePiranhaManager();
app.UseMvc(routes =>
{
...
});
...
}
The important part here is the order in which the middleware is registered. The current security
component should always be registered before the rest of the Piranha middleware, and the rest of the Piranha middleware should be registered before MVC. This is needed as the Piranha middleware re-writes the request and passes it on to to the underlying web framework.