Add project files.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ObservableCollectionViewModel :
|
||||
ObservableCollection<object>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class AppService(IEnumerable<IInitializer> initializers) :
|
||||
IHostedService
|
||||
{
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public record DataTemplateDescriptor :
|
||||
IDataTemplateDescriptor
|
||||
{
|
||||
public required Type DataType { get; set; }
|
||||
|
||||
public required Type TemplateType { get; set; }
|
||||
|
||||
public required object Key { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IDataTemplateDescriptor
|
||||
{
|
||||
Type DataType { get; set; }
|
||||
object Key { get; set; }
|
||||
Type TemplateType { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IInitializer
|
||||
{
|
||||
Task InitializeAsync();
|
||||
}
|
||||
|
||||
public interface IDataTemplateSelector
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddDataTemplate<TData, TTemplate>(this IServiceCollection services,
|
||||
object? key = null)
|
||||
{
|
||||
Type dataType = typeof(TData);
|
||||
Type templateType = typeof(TTemplate);
|
||||
|
||||
key ??= dataType.Name;
|
||||
|
||||
services.AddKeyedTransient(dataType, key);
|
||||
services.AddKeyedTransient(templateType, key);
|
||||
|
||||
services.AddTransient<IDataTemplateDescriptor>(provider => new DataTemplateDescriptor
|
||||
{
|
||||
DataType = dataType,
|
||||
TemplateType = templateType,
|
||||
Key = key
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface ITemplateFactory
|
||||
{
|
||||
object? Create(object key);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface ITemplatedViewModel
|
||||
{
|
||||
ITemplateFactory TemplateFactory { get; }
|
||||
}
|
||||
Reference in New Issue
Block a user