This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppTests | |
{ | |
private readonly TestHost _host; | |
public AppTests() | |
{ | |
_host = new TestHost() | |
.ConfigureServices(services => | |
{ | |
services.AddSingleton<INavigationService, TestNavigationService>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void ProfileViewModel_UpdatesProfileCorrectly() | |
{ | |
// Arrange | |
var mockService = new Mock<IUserService>(); | |
mockService.Setup(x => x.UpdateProfile(It.IsAny<Profile>())) | |
.ReturnsAsync(true); | |
var vm = new ProfileViewModel(mockService.Object); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DbUnitOfWork : IDisposable | |
{ | |
private readonly SqliteConnection _connection; | |
public DbUnitOfWork(IConfiguration config) | |
{ | |
_connection = new SqliteConnection(config.GetConnectionString()); | |
_connection.Open(); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddScoped<IAuthService, AuthService>(); | |
services.AddSingleton<ITokenCache, SecureTokenCache>(); | |
services.AddTransient<ILoginValidator, LoginValidator>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddSingleton<ILazyService>(sp => | |
new LazyServiceWrapper(() => | |
sp.GetRequiredService<IOtherService>())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Log service lifetimes | |
builder.Services.AddLogging(log => | |
log.AddFilter("Microsoft.Extensions.DependencyInjection", LogLevel.Debug)); | |
// Inspect container | |
var serviceDescriptors = builder.Services | |
.Where(s => s.ServiceType == typeof(IMyService)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IDeviceInfo | |
{ | |
string Model { get; } | |
string Platform { get; } | |
} | |
// Platform implementations | |
#if ANDROID | |
public class AndroidDeviceInfo : IDeviceInfo { ... } | |
#elif IOS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.Services.AddUserProfileModule(); | |
builder.Services.AddCheckoutModule(); | |
// Module extension method | |
public static IServiceCollection AddUserProfileModule(this IServiceCollection services) | |
{ | |
services.AddScoped<IUserService, UserService>(); | |
services.AddTransient<UserProfileViewModel>(); | |
return services; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lightweight service | |
public class AnalyticsService : IAnalyticsService | |
{ | |
private readonly ILogger _logger; | |
// Dependencies injected | |
public AnalyticsService(ILogger<AnalyticsService> logger) | |
{ | |
_logger = logger; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserSession : IDisposable | |
{ | |
public Guid SessionId { get; } = Guid.NewGuid(); | |
public DateTime Created { get; } = DateTime.UtcNow; | |
public void Dispose() | |
{ | |
// Cleanup session resources | |
} | |
} |