namespace zero.Architecture; public class BlueprintService : IBlueprintService { protected IZeroOptions Options { get; set; } protected IReadOnlyCollection Blueprints { get; set; } public BlueprintService(IZeroOptions options) { Options = options; Blueprints = Options.For(); } /// public bool IsEnabled(T model) => IsEnabled(model.GetType()); /// public bool IsEnabled()=> IsEnabled(typeof(T)); /// public bool IsEnabled(Type type) => Blueprints.Any(x => x.ContentType.IsAssignableFrom(type)); /// public bool TryGetBlueprint(T model, out Blueprint blueprint) => TryGetBlueprint(model.GetType(), out blueprint); /// public bool TryGetBlueprint(out Blueprint blueprint) => TryGetBlueprint(typeof(T), out blueprint); /// public bool TryGetBlueprint(Type type, out Blueprint blueprint) { blueprint = Blueprints.FirstOrDefault(x => x.ContentType.IsAssignableFrom(type)); return blueprint != null; } /// public Dictionary GetAllBlueprints() { return Blueprints.ToDictionary(x => x.ContentType, x => x); } } public interface IBlueprintService { /// /// Check whether blueprinting functionality is enabled for a certain entity /// bool IsEnabled(); /// /// Check whether blueprinting functionality is enabled for a certain entity /// bool IsEnabled(T model); bool IsEnabled(Type type); bool TryGetBlueprint(T model, out Blueprint blueprint); bool TryGetBlueprint(out Blueprint blueprint); bool TryGetBlueprint(Type type, out Blueprint blueprint); /// /// Get all registered blueprint configurations /// Dictionary GetAllBlueprints(); }