Build a strong foundation in .NET Core development and cross-platform programming.
Build a strong foundation in .NET Core development and cross-platform programming.
Understand .NET Core's evolution, architecture, and its role in modern cross-platform development
Content by: Sunny Radadiya
.Net Developer
.NET Core is a free, open-source, cross-platform framework for building modern applications. It's a redesign of .NET Framework that runs on Windows, macOS, and Linux, providing a unified development experience across platforms.
**Key Differences:** **Platform Support:** - .NET Core: Cross-platform (Windows, macOS, Linux) - .NET Framework: Windows-only **Deployment:** - .NET Core: Self-contained deployments, framework-dependent deployments - .NET Framework: Requires framework installation **Performance:** - .NET Core: Optimized for performance and memory usage - .NET Framework: Legacy performance characteristics **API Surface:** - .NET Core: Streamlined, modern APIs - .NET Framework: Larger, legacy API surface **Development:** - .NET Core: Modern tooling, CLI-first approach - .NET Framework: Visual Studio-centric development
Test your understanding of this topic:
Learn how .NET Core enables true cross-platform development and deployment
Content by: Akash Vadher
.Net Developer
While .NET Core provides cross-platform capabilities, understanding platform-specific differences is crucial for building robust applications.
using System;
using System.Runtime.InteropServices;
public class PlatformDetection
{
public static void Main()
{
Console.WriteLine($"OS: {RuntimeInformation.OSDescription}");
Console.WriteLine($"Architecture: {RuntimeInformation.OSArchitecture}");
Console.WriteLine($"Process Architecture: {RuntimeInformation.ProcessArchitecture}");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("Running on Windows");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Console.WriteLine("Running on Linux");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Console.WriteLine("Running on macOS");
}
}
}
Test your understanding of this topic:
Master the .NET Core CLI tools for project management, building, and deployment
Content by: Vaibhav Nakrani
.Net Developer
The .NET CLI is a cross-platform toolchain for developing .NET applications. It provides commands for creating, building, running, and publishing applications.
# Create a new project
dotnet new console -n MyApp
dotnet new webapi -n MyWebApi
dotnet new classlib -n MyLibrary
# Add packages
dotnet add package Newtonsoft.Json
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
# Remove packages
dotnet remove package Newtonsoft.Json
# List installed packages
dotnet list package
# Restore dependencies
dotnet restore
# Build the project
dotnet build
# Run the project
dotnet run
# Publish the project
dotnet publish -c Release -r win-x64 --self-contained true
# Create a solution
dotnet new sln -n MySolution
# Add projects to solution
dotnet sln add MyApp/MyApp.csproj
dotnet sln add MyLibrary/MyLibrary.csproj
# Remove project from solution
dotnet sln remove MyApp/MyApp.csproj
# List solution projects
dotnet sln list
# Build entire solution
dotnet build MySolution.sln
Test your understanding of this topic:
Understand .NET Core project structure, configuration system, and best practices
Content by: Dipen Dalvadi
.Net Developer
MyApp/
āāā Program.cs # Application entry point
āāā MyApp.csproj # Project file
āāā appsettings.json # Configuration file
āāā appsettings.Development.json
āāā Properties/
ā āāā launchSettings.json # Launch configuration
āāā Controllers/ # MVC Controllers (if applicable)
āāā Models/ # Data models
āāā Services/ # Business logic services
āāā wwwroot/ # Static files (web apps)
āāā bin/ # Build output
āāā Debug/
āāā net6.0/
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
public class Program
{
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
config.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json",
optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
config.AddCommandLine(args);
})
.ConfigureServices((context, services) =>
{
// Register services here
services.Configure<MyOptions>(context.Configuration.GetSection("MyOptions"));
});
}
Test your understanding of this topic:
Learn .NET Core's built-in dependency injection container and how to use it effectively
Content by: Sunny Radadiya
.Net Developer
Dependency Injection (DI) is a design pattern that implements Inversion of Control (IoC) for resolving dependencies. .NET Core has a built-in DI container that makes it easy to manage dependencies throughout your application.
// Transient: New instance every time
services.AddTransient<IMyService, MyService>();
// Scoped: One instance per request (web apps)
services.AddScoped<IMyService, MyService>();
// Singleton: One instance for the entire application
services.AddSingleton<IMyService, MyService>();
// Example implementation
public interface IEmailService
{
Task SendEmailAsync(string to, string subject, string body);
}
public class EmailService : IEmailService
{
public async Task SendEmailAsync(string to, string subject, string body)
{
// Email sending logic
await Task.CompletedTask;
}
}
// Registration
services.AddScoped<IEmailService, EmailService>();
// Factory pattern
services.AddTransient<Func<string, ILogger>>(provider => key =>
provider.GetService<ILoggerFactory>().CreateLogger(key));
// Options pattern
services.Configure<DatabaseOptions>(configuration.GetSection("Database"));
// Multiple implementations
services.AddTransient<INotificationService, EmailNotificationService>();
services.AddTransient<INotificationService, SmsNotificationService>();
// Decorator pattern
services.AddTransient<INotificationService, LoggingNotificationService>();
services.Decorate<INotificationService, CachingNotificationService>();
Test your understanding of this topic:
Master .NET Core's configuration system and settings management
Content by: Akash Vadher
.Net Developer
`.NET Core supports multiple configuration sources that are loaded in a specific order, with later sources overriding earlier ones.
// JSON files
config.AddJsonFile("appsettings.json");
config.AddJsonFile("appsettings.Development.json", optional: true);
// Environment variables
config.AddEnvironmentVariables();
// Command line arguments
config.AddCommandLine(args);
// User secrets (development only)
config.AddUserSecrets<Program>();
// Azure Key Vault
config.AddAzureKeyVault(vaultUrl, clientId, clientSecret);
// Custom provider
config.Add(new CustomConfigurationProvider());
// Define configuration class
public class DatabaseOptions
{
public const string SectionName = "Database";
public string ConnectionString { get; set; }
public int CommandTimeout { get; set; } = 30;
public bool EnableRetryOnFailure { get; set; } = true;
}
// Register in DI container
services.Configure<DatabaseOptions>(
configuration.GetSection(DatabaseOptions.SectionName));
// Use in your service
public class DataService
{
private readonly DatabaseOptions _options;
public DataService(IOptions<DatabaseOptions> options)
{
_options = options.Value;
}
public void Connect()
{
// Use _options.ConnectionString
}
}
Test your understanding of this topic:
Continue your learning journey and master the next set of concepts.
Continue to Module 2