-
-
Notifications
You must be signed in to change notification settings - Fork 219
First Application
Huy Nguyen edited this page Apr 5, 2025
·
2 revisions
This tutorial will guide you through creating your first Mixcore CMS application from scratch.
- Completed Development Environment Setup
- Basic understanding of C# and .NET
- SQL Server installed and running
-
Open your terminal and navigate to your workspace:
mkdir MyFirstMixcoreApp cd MyFirstMixcoreApp
-
Create a new Mixcore application:
dotnet new mixcore-app -n MyFirstApp
-
Add the application to the solution:
dotnet sln add MyFirstApp/MyFirstApp.csproj
-
Open
appsettings.json
in your application:{ "ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=mixcore;Trusted_Connection=True;" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*" }
-
Update the database connection string to match your environment.
-
Create a new module using the Mixcore CLI:
dotnet new mixcore-module -n MyFirstModule
-
Add the module to your application:
dotnet add MyFirstApp/MyFirstApp.csproj reference MyFirstModule/MyFirstModule.csproj
-
Register the module in
Startup.cs
:public void ConfigureServices(IServiceCollection services) { // ... existing code ... services.AddMixcoreModule<MyFirstModule>(); }
-
Create a new page in your module:
// MyFirstModule/Pages/Index.cshtml.cs public class IndexModel : PageModel { public void OnGet() { ViewData["Title"] = "My First Mixcore Page"; } }
-
Create the corresponding view:
@* MyFirstModule/Pages/Index.cshtml *@ @page @model MyFirstModule.Pages.IndexModel @{ ViewData["Title"] = "My First Mixcore Page"; } <div class="container"> <h1>Welcome to My First Mixcore Application!</h1> <p>This is your first custom page in Mixcore CMS.</p> </div>
-
Create a service interface:
// MyFirstModule/Services/IMyService.cs public interface IMyService { string GetWelcomeMessage(); }
-
Implement the service:
// MyFirstModule/Services/MyService.cs public class MyService : IMyService { public string GetWelcomeMessage() { return "Hello from MyService!"; } }
-
Register the service in your module:
// MyFirstModule/Module.cs public class Module : IMixcoreModule { public void ConfigureServices(IServiceCollection services) { services.AddScoped<IMyService, MyService>(); } }
-
Use the service in your page:
// MyFirstModule/Pages/Index.cshtml.cs public class IndexModel : PageModel { private readonly IMyService _myService; public IndexModel(IMyService myService) { _myService = myService; } public string WelcomeMessage { get; set; } public void OnGet() { WelcomeMessage = _myService.GetWelcomeMessage(); ViewData["Title"] = "My First Mixcore Page"; } }
-
Update the view to display the message:
@* MyFirstModule/Pages/Index.cshtml *@ <div class="container"> <h1>Welcome to My First Mixcore Application!</h1> <p>@Model.WelcomeMessage</p> </div>
-
Build the application:
dotnet build
-
Run the application:
dotnet run --project MyFirstApp
-
Open your browser and navigate to:
http://localhost:5000
- Visit our Community Forum
- Check the Troubleshooting Guide
- Contact Support for enterprise assistance