.NET HELP

dotnetify.NET (How It Works For Developers)

Published August 13, 2024
Share:

Introduction

DotNetify is an open-source framework made with .NET and Blazor that is intended for creating real-time web applications on a .NET platform. Utilizing SignalR's power for real-time interactions between the client and server makes it easier to construct dynamic and interactive web applications. DotNetify is a programming model that synchronizes client-side views with server-side scripting data, allowing developers to quickly and easily design rich, responsive, and performant online interfaces.

Conversely, IronPDF PDF Generation Library is a potent .NET package that makes it easier to create, edit, and manipulate PDF documents programmatically. It is a great option for creating dynamic, data-driven documents like reports, invoices, and forms since it provides an intuitive API for transforming HTML text into PDFs.

Real-time web interactivity and powerful PDF production capabilities are combined in a C# application by integrating DotNetify with IronPDF. Applications that demand real-time data display and the ability to dynamically create and distribute PDF documents based on the most recent data will find this integration especially helpful. Developers may design extensive, interactive online apps that address complicated business requirements and improve user experiences through seamless document generation and distribution by leveraging IronPDF's versatile PDF generation and DotNetify's real-time data synchronization.

What is DotNetify?

DotNetify is an open-source framework made to make it easier to create interactive, real-time web apps with .NET and Blazor. Developers may create dynamic and responsive user interfaces that synchronize with server-side data effortlessly by utilizing SignalR, which facilitates real-time communication between the client and server. DotNetify is a reactive programming approach that simplifies the creation of complicated online applications with little code by abstracting the difficulties of real-time data binding and event handling.

dotnetify .NET (How It Works For Developers): Figure 1

To guarantee that the user interface always represents the state of the application, DotNetify allows developers to construct view models on the server that immediately propagate changes to the client. This framework allows for flexibility in selecting the client-side technology, supporting both classic JavaScript front-ends and Blazor front-ends. It is perfect for applications that need real-time updates, such as dashboards, collaborative tools, and live data streams, because of its ease of use and effectiveness.

DotNetify's real-time handling of intricate interactions and data flows greatly improves user experience by enabling smooth data synchronization and immediate feedback. All things considered, DotNetify is a useful solution for .NET developers who want to build reactive, cutting-edge, real-time online applications quickly and effectively.

Features of DotNetify

A number of features provided by DotNetify in C# make it easier to create interactive, real-time online apps. Important characteristics consist of:

Real-Time Communication: DotNetify makes use of SignalR to facilitate bi-directional, real-time communication between the client and server, enabling interactive user interfaces and quick updates.

Reactive Programming Model: It offers a reactive programming method in which client-side views and server-side view models automatically synchronize to keep the user interface up to current with the most recent information.

Server-Side View Models: This makes it possible for developers to create server-side view models that client-side components may bind to, making state management and data flow within the application simpler.

Blazor and JavaScript Support: Supports both classic JavaScript front-ends and Blazor front-ends, allowing developers to select the client-side technology that best fits their requirements.

Ease of Integration: Real-time functionality may be easily added to new or existing projects thanks to its seamless integration with existing .NET applications. It also integrates well with front-end UI component frameworks like WebSockets for creating a web component and works with projects using software such as React Native, Vue, and Blazor.

Scalability: DotNetify, which is based on SignalR, inherits its scalability features, enabling applications to effectively manage a high number of concurrent connections.

MVVM Architecture: Supports the Model-View-ViewModel (MVVM) architecture, which aids in the division of responsibilities and the clean, maintainable organization of code.

Event Handling: Reduces the amount of boilerplate code required to handle UI interactions and state changes by streamlining event handling and data binding.

Extensible and Customizable: Offers extensibility points and hooks to allow for behavior customization and necessary integration with other libraries or frameworks.

Strong Infrastructure: The DotNetify infrastructure offers a dynamic routing mechanism that is capable of being defined entirely on the back end, which is capable of nested routing, token-based authentication, and more.

Open Source and Community-Driven: DotNetify is an open-source project that gains from community participation and contributions, which guarantees ongoing upgrades and enhancements.

Create and Configure DotNetify C#

To establish a simple project and begin configuring DotNetify in a C# online application, proceed as follows. This tutorial will show you how to use ASP.NET Core and Blazor to put up a basic DotNetify server and client.

Set Up a New ASP.NET Core Blazor Server Project

  • Open Visual Studio: Launch Visual Studio, then start a fresh project.
  • Create a Blazor Server App: Click "Next" after selecting the Blazor Server App template from the project templates.
  • Configure Your Project: Give your project a name (like "DotNetifyWebApp") and make the necessary configuration changes. Press "Create."

Install DotNetify via NuGet

  • Manage NuGet Packages: Go to "Manage NuGet Packages" from the Solution Explorer by performing a right-click on your project.
  • Search for DotNetify: Install the DotNetify and DotNetify.Blazor packages.

Configure DotNetify

To configure DotNetify, open Startup.cs and use the ConfigureServices and Configure methods.

using DotNetify;
using DotNetify.Blazor;
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddSignalR();
        services.AddDotNetify();
    }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
            endpoints.MapHub<DotNetifyHub>("/dotnetify");
        });
    }
}
using DotNetify;
using DotNetify.Blazor;
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddSignalR();
        services.AddDotNetify();
    }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
            endpoints.MapHub<DotNetifyHub>("/dotnetify");
        });
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Create a ViewModel

Create a new class file in your project (HelloWorldViewModel.cs, for example) and design a basic ViewModel.

using DotNetify;
public class HelloWorldViewModel : BaseVM
{
    public string Greetings => "Hello, World!";
}
using DotNetify;
public class HelloWorldViewModel : BaseVM
{
    public string Greetings => "Hello, World!";
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Register ViewModel

Before registering the ViewModel, open Program.cs.

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .ConfigureServices(services =>
            {
                services.AddTransient<HelloWorldViewModel>();
            });
}
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .ConfigureServices(services =>
            {
                services.AddTransient<HelloWorldViewModel>();
            });
}
Imports Microsoft.AspNetCore.Hosting
Imports Microsoft.Extensions.DependencyInjection
Imports Microsoft.Extensions.Hosting
Public Class Program
	Public Shared Sub Main(ByVal args() As String)
		CreateHostBuilder(args).Build().Run()
	End Sub
	Public Shared Function CreateHostBuilder(ByVal args() As String) As IHostBuilder
		Return Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(Sub(webBuilder)
				webBuilder.UseStartup(Of Startup)()
		End Sub).ConfigureServices(Sub(services)
				services.AddTransient(Of HelloWorldViewModel)()
		End Sub})
	End Function
VB   C#

Create Blazor Component

In your project, add a new Blazor component (such as HelloWorld.razor) and connect it to the ViewModel.

@page "/"
@using DotNetify
@using DotNetify.Blazor
@inject IDotNetifyService DotNetify
<h3>@greetings</h3>
@code {
    private string greetings;
    protected override async Task OnInitializedAsync()
    {
        var vm = await DotNetify.ConnectAsync<HelloWorldViewModel>(this);
        greetings = vm.Greetings;
    }
}
@page "/"
@using DotNetify
@using DotNetify.Blazor
@inject IDotNetifyService DotNetify
<h3>@greetings</h3>
@code {
    private string greetings;
    protected override async Task OnInitializedAsync()
    {
        var vm = await DotNetify.ConnectAsync<HelloWorldViewModel>(this);
        greetings = vm.Greetings;
    }
}
'INSTANT VB TODO TASK: The following line could not be converted:
page "/" [using] DotNetify [using] DotNetify.Blazor inject IDotNetifyService DotNetify (Of h3) greetings</h3> code
If True Then
	private String greetings
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'	protected override async Task OnInitializedAsync()
'	{
'		var vm = await DotNetify.ConnectAsync<HelloWorldViewModel>(Me);
'		greetings = vm.Greetings;
'	}
End If
VB   C#

Sets up the application to utilize DotNetify, Blazor, Razor Pages, and SignalR. Additionally, it configures DotNetify and Blazor endpoints and routing. Describes a basic ViewModel with a greeting message-returning attribute. The HelloWorldViewModel is registered as a temporary service. Blazor component that establishes a connection with the HelloWorldViewModel, gets the welcome text, and puts it on the screen.

dotnetify .NET (How It Works For Developers): Figure 2

Getting Started

You must create a .NET project and incorporate both libraries into your application in order to use DotNetify and IronPDF. Here's a step-by-step tutorial to get you going:

What is IronPDF?

The feature-rich .NET library IronPDF PDF Library allows C# programs to produce, read, and edit PDF documents. With this program, developers can quickly turn HTML, CSS, and JavaScript information into high-quality, print-ready PDFs. Among the most crucial tasks are adding headers and footers, dividing and combining PDFs, adding watermarks to documents, and converting HTML to PDF.

IronPDF is helpful for a variety of applications because it supports both .NET Framework and .NET Core. With their simplicity of use and wealth of information, PDFs allow developers to easily integrate them into their products. Because IronPDF can handle complex data layouts and formatting, the PDFs it generates as an output are quite similar to the client's original HTML text. IronPDF also supports cross-platform apps like Windows, web, and mobile environments.

dotnetify .NET (How It Works For Developers): Figure 3

Features of IronPDF

PDF Generation from HTML

Convert JavaScript, HTML, and CSS to PDF. IronPDF supports media queries and responsive design, two contemporary web standards. Its support for modern web standards is useful for dynamically decorating PDF bills, reports, and documents with HTML and CSS.

PDF Editing

Pre-existing PDFs can have text, images, and other content added to them. Developers can use IronPDF to take text and images out of PDF files, combine numerous PDFs into one file, divide PDF files into multiple separate papers, and include watermarks, annotations, headers, and footers.

PDF Conversion

Convert several file formats, including Word, Excel, and picture files, to PDF format. IronPDF also supports PDF to image conversion (PNG, JPEG, etc.).

Performance and Reliability

High performance and dependability are desired design qualities in industrial settings. With IronPDF, developers can manage big document sets with ease.

Install IronPDF

To gain the tools you need to work with PDFs in .NET projects, install the IronPDF package.

dotnet add package IronPdf
dotnet add package IronPdf
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'dotnet add package IronPdf
VB   C#

Integrate DotNetify with IronPDF

Configure DotNetify

Startup Configuration: Open Startup.cs, then use the ConfigureServices and Configure methods to set up DotNetify.

using DotNetify;
using DotNetify.Blazor;
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddSignalR();
        services.AddDotNetify();
    }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
            endpoints.MapHub<DotNetifyHub>("/dotnetify");
        });
    }
}
using DotNetify;
using DotNetify.Blazor;
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddSignalR();
        services.AddDotNetify();
    }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
            endpoints.MapHub<DotNetifyHub>("/dotnetify");
        });
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Create a View Model

In your project, add a new class file (such as PdfViewModel.cs) and create a ViewModel that will produce a PDF.

using DotNetify;
using IronPdf;
public class PdfViewModel : BaseVM
{
    public string PdfUrl { get; set; }
    public void GeneratePdf()
    {
        var Renderer = new ChromePdfRenderer();
        var PdfDocument = Renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");
        var OutputPath = "wwwroot/PdfFiles/HelloWorld.pdf";
        PdfDocument.SaveAs(OutputPath);
        PdfUrl = "/PdfFiles/HelloWorld.pdf";
        Changed(nameof(PdfUrl));
    }
}
using DotNetify;
using IronPdf;
public class PdfViewModel : BaseVM
{
    public string PdfUrl { get; set; }
    public void GeneratePdf()
    {
        var Renderer = new ChromePdfRenderer();
        var PdfDocument = Renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>");
        var OutputPath = "wwwroot/PdfFiles/HelloWorld.pdf";
        PdfDocument.SaveAs(OutputPath);
        PdfUrl = "/PdfFiles/HelloWorld.pdf";
        Changed(nameof(PdfUrl));
    }
}
Imports DotNetify
Imports IronPdf
Public Class PdfViewModel
	Inherits BaseVM

	Public Property PdfUrl() As String
	Public Sub GeneratePdf()
		Dim Renderer = New ChromePdfRenderer()
		Dim PdfDocument = Renderer.RenderHtmlAsPdf("<h1>Hello World!</h1>")
		Dim OutputPath = "wwwroot/PdfFiles/HelloWorld.pdf"
		PdfDocument.SaveAs(OutputPath)
		PdfUrl = "/PdfFiles/HelloWorld.pdf"
		Changed(NameOf(PdfUrl))
	End Sub
End Class
VB   C#

Add a new Blazor component to your project (such as GeneratePdf.razor) and bind it to the ViewModel to create a Blazor component.

@page "/"
@using DotNetify
@using DotNetify.Blazor
@inject IDotNetifyService DotNetify
<PageTitle>Generate PDF</PageTitle>
<h3>Generate PDF</h3>
<button @onclick="GeneratePdf">Generate PDF</button>
@if (!string.IsNullOrEmpty(pdfUrl))
{
    <a href="@pdfUrl" target="_blank">Download PDF</a>
}
@code {
    private string pdfUrl;
    protected override async Task OnInitializedAsync()
    {
        var vm = await DotNetify.ConnectAsync<PdfViewModel>(this);
        pdfUrl = vm.PdfUrl;
        vm.PropertyChanged += (sender, args) =>
        {
            if (args.PropertyName == nameof(vm.PdfUrl))
            {
                pdfUrl = vm.PdfUrl;
                StateHasChanged();
            }
        };
    }
    private void GeneratePdf()
    {
        DotNetify.CallMethod("GeneratePdf");
    }
}
@page "/"
@using DotNetify
@using DotNetify.Blazor
@inject IDotNetifyService DotNetify
<PageTitle>Generate PDF</PageTitle>
<h3>Generate PDF</h3>
<button @onclick="GeneratePdf">Generate PDF</button>
@if (!string.IsNullOrEmpty(pdfUrl))
{
    <a href="@pdfUrl" target="_blank">Download PDF</a>
}
@code {
    private string pdfUrl;
    protected override async Task OnInitializedAsync()
    {
        var vm = await DotNetify.ConnectAsync<PdfViewModel>(this);
        pdfUrl = vm.PdfUrl;
        vm.PropertyChanged += (sender, args) =>
        {
            if (args.PropertyName == nameof(vm.PdfUrl))
            {
                pdfUrl = vm.PdfUrl;
                StateHasChanged();
            }
        };
    }
    private void GeneratePdf()
    {
        DotNetify.CallMethod("GeneratePdf");
    }
}
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'@page "/" @using DotNetify @using DotNetify.Blazor @inject IDotNetifyService DotNetify (Of PageTitle) Generate PDF</PageTitle> (Of h3) Generate PDF</h3> <button @onclick="GeneratePdf"> Generate PDF</button> @if(!string.IsNullOrEmpty(pdfUrl))
'{
'	<a href="@pdfUrl" target="_blank"> Download PDF</a>
'}
code
If True Then
	private String pdfUrl
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'	protected override async Task OnInitializedAsync()
'	{
'		var vm = await DotNetify.ConnectAsync<PdfViewModel>(Me);
'		pdfUrl = vm.PdfUrl;
'		vm.PropertyChanged += (sender, args) =>
'		{
'			if (args.PropertyName == nameof(vm.PdfUrl))
'			{
'				pdfUrl = vm.PdfUrl;
'				StateHasChanged();
'			}
'		};
'	}
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
'	private void GeneratePdf()
'	{
'		DotNetify.CallMethod("GeneratePdf");
'	}
End If
VB   C#

Real-time data handling and dynamic PDF production are made possible by the integration of DotNetify and IronPDF in a C# ASP.NET Core Blazor application. To enable server-side Blazor and real-time features, the first step in the setup is to configure the project in Startup.cs, where services for Razor Pages, Blazor Server, SignalR, and DotNetify are registered.

IronPDF's PDF generation logic is defined in the PdfViewModel.cs ViewModel. Only a few lines of code are enough to generate the PDF file. One of its features is the GeneratePdf function, which takes HTML information and turns it into a PDF. It stores the file on the server and updates the PdfUrl property to let the client know where the new file is. This ViewModel communicates with the GeneratePdf.razor Blazor component.

dotnetify .NET (How It Works For Developers): Figure 4

In order to enable the client to call the GeneratePdf function and react to property changes, it connects to PdfViewModel via the IDotNetifyService and binds to its properties. The component invokes the ViewModel's method when the user hits the "Generate PDF" button, creating the PDF and dynamically updating the download URL. With this configuration, the web application offers a responsive and engaging user experience by integrating the potent document-generating capabilities of IronPDF with the real-time data synchronization of DotNetify.

dotnetify .NET (How It Works For Developers): Figure 5

Conclusion

Real-time data synchronization and dynamic PDF production are combined in a C# ASP.NET Core Blazor application by integrating DotNetify with IronPDF. Applications that are interactive and responsive are made possible by DotNetify, which enables smooth communication between client-side Blazor components and server-side ViewModels. This is enhanced by IronPDF, which offers powerful tools for creating and modifying PDFs straight from server-side logic. With the help of this potent mix, developers may create apps that can create and send unique documents as well as an updates in real-time.

This integration makes the most of real-time data handling and document-generating technologies to improve user experience, whether it is for reporting, invoicing, or any other document-related operation. Developers may set up and use these tools quickly and easily by following the procedures listed, which opens up a world of possibilities for contemporary web application development.

You can utilize OCR, barcode scanning, PDF production, Excel connection, and much more with IronPDF and IronSoftware Developer Tools for developers looking to try out its extensive set of features.

Provided license alternatives related to the project are specified in detail, developers will have an easier time choosing the best model. The aforementioned advantages facilitate the timely, coordinated, and effective implementation of solutions by developers for a variety of problems.

< PREVIOUS
Grapevine .NET (How It Works For Developers)
NEXT >
FiddlerCore .NET (How It Works For Developers)

Ready to get started? Version: 2024.12 just released

Free NuGet Download Total downloads: 11,622,374 View Licenses >