Lara is a library for developing web user interfaces. Lara gives you full control of the client's HTML Document Object Model (DOM) from the server in C#, and avoids page reloads by exchanging differentials between server and client.
"It is similar to server-side Blazor, but is much more lightweight and easier to install. For example, while any type of Blazor requires a whole SDK, Lara is just a NuGet package." ScientificProgrammer.net
using Integrative.Lara;
using System.Threading.Tasks;
namespace SampleProject
{
class Program
{
static async Task Main()
{
using var app = new Application();
await app.Start(new StartServerOptions
{
Port = 8182,
// looks for classes decorated with 'Lara' attributes
PublishAssembliesOnStart = true
});
await app.WaitForShutdown();
}
}
[LaraPage(Address = "/")]
class MyPage : IPage
{
int counter = 0;
public Task OnGet()
{
var button = Element.Create("button");
button.InnerText = "Click me";
button.On("click", () =>
{
counter++;
button.InnerText = $"Clicked {counter} times";
return Task.CompletedTask;
});
LaraUI.Page.Document.Body.AppendChild(button);
return Task.CompletedTask;
}
}
}
Other resources available for building web pages are the LaraBuilder class, Web Components, and Reactive Programming.
To add Lara to an existing ASP.NET Core server, add to the Startup class or equivalent:
private readonly Application _laraApp = new Application();
public void Configure(IApplicationBuilder app)
{
app.UseLara(_laraApp, new LaraOptions
{
// configuration options
});
}
To create a desktop container for your web app, here's a few options:
- electron.js combined with electron-cgi library
- Chromely
- neutralinojs
There's no need to download this repository to use Lara, instead, there's a NuGet package.
To start, create a new project and add the NuGet package Integrative.Lara
. In Visual Studio go to Tools -> NuGet Package Manager -> Manage NuGet packages for Solution, then search for the package 'Integrative.Lara'.
In your project, copy and paste the sample application.
This repository contains a sample project.
The wiki has the documentation for using Lara.
Whenever the browser triggers a registered event (e.g. click on a button), it sends to the server a message saying that the button was clicked. The server executes the code associated with the event, manipulating the server's copy of the page, and replies a JSON message with the delta between server and client.
The source code contains a sample project. The documentation is available in the wiki.
Please send feedback! Issues, questions, suggestions, requests for features, and success stories. Please let me know by either opening an issue or by direct message. Thank you!
If you like Lara, please give it a star - it helps!
Thanks to JetBrains for the licenses of Rider and DotCover.