Startup.cs

Lynicon can be configured like any other module or application in ASP.Net Core by changes to the Startup.cs file. The changes required to the different standard methods in the Startup class are listed below:

Constructor

public Startup(IHostingEnvironment env)
{
	...
	env.ConfigureLog4Net("log4net.xml");
}

The line shown above should be added at the end of the constructor for the Startup class to load the configuration for log4net, the logging system used by Lynicon.

ConfigureServices

public void ConfigureServices(IServiceCollection services)
{
	...

	services.AddIdentity<User, IdentityRole>()
    	.AddDefaultTokenProviders();

	services.AddMvc(options => options.AddLyniconOptions())
                .AddApplicationPart(typeof(LyniconSystem).Assembly);

	services.AddAuthorization(options =>
                options.AddLyniconAuthorization());

	services.AddLynicon(options =>
                options.UseConfiguration(Configuration.GetSection("Lynicon:Core"))
                    .UseModule<CoreModule>()
                    )
                .AddLyniconIdentity();
}

The above 4 lines are additions or modifications of lines which may already be in Startup.cs according to how the site was set up or later configured.

  • Ensure services.AddIdentity<,>() is called here. Don't use the configuration method AddEntityFrameworkStores<ApplicationDbContext>() as the appropriate entity framework stores for the user system are set up in the call to AddLyniconIdentity() later. This sets up Identity Framework for user management as used by Lynicon.
  • Ensure AddMvc() is called here with the options lambda, calling at least AddLyniconOptions() to set up MVC for Lynicon.  This call sets up custom binding providers and a custom metadata provider for Lynicon. Call AddApplicationPart for all Lynicon assemblies in the project, at least the core Lynicon assembly.
  • Ensure AddAuthorization() is called here with the options lambda, allowing you to call AddLyniconAuthorization to set up the default options for Lynicon authorization. See Custom Permissions for how to customise Lynicon's use of the Policy-based authorization in ASP.Net Core.
  • Finally ensure .AddLynicon() is called to set up services for Lynicon itself.  The final AddLyniconIdentity() is used to set up a custom ASP.Net Identity-based membership system for Lynicon.

The Lynicon options configuration methods include the following:

Configuration MethodPurpose
UseConfiguration(IConfigurationSection section)Load the specified configuration section into Lynicon's core options
UseModule<TModule>(params object[] moduleParams)Load the specified module of type TModule into Lynicon, using a list of configuration parameters dependent on the module
UseTypeSetup(Action<ITypeSystemRegistrar> setupTypes)Use the given action to set up any number of custom type configurations. See Data System Configuration

To see the possible methods for setting up membership systems see Setting Up User Management

Configure

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime life)
{
	...
    app.UseIdentity();

	...

    app.ConstructLynicon();

    app.UseMvc(routes =>
    {
    	routes.MapLyniconRoutes();
    	routes.MapDataRoute<TestContent>("test", "test/{_0}", new { controller = "Test", action = "Index" });
    	routes.MapDataRoute<HeaderContent>("header", "test/{_0}", new { controller = "Test", action = "Header" });
    	routes.MapRoute(
    		name: "default",
    		template: "{controller=Home}/{action=Index}/{id?}");
    });

    app.InitialiseLynicon(life);
}

Ensure the parameters for this setup method include IApplicationLifetime as some Lynicon modules may need to perform actions on application shutdown.

The ConstructLynicon() method is used to construct instances of all modules Lynicon will use.

Ensure that UseMvc() is called to initialise MVC. Routing setup withing this call is modified to all an initial call to .MapLyniconRoutes() to create all service endpoints Lynicon and its modules need. Then you have the option to use the MapDataRoute<TContent>() extension method to create routes which are content managed.  See Content Routing for details on how this works.

The InitialiseLynicon(life) method then sets up membership, sets up content types, initialises all modules, and builds the data system.