Apps.Contextsphere.Uwp
1.0.2
dotnet add package Apps.Contextsphere.Uwp --version 1.0.2
NuGet\Install-Package Apps.Contextsphere.Uwp -Version 1.0.2
<PackageReference Include="Apps.Contextsphere.Uwp" Version="1.0.2" />
paket add Apps.Contextsphere.Uwp --version 1.0.2
#r "nuget: Apps.Contextsphere.Uwp, 1.0.2"
// Install Apps.Contextsphere.Uwp as a Cake Addin #addin nuget:?package=Apps.Contextsphere.Uwp&version=1.0.2 // Install Apps.Contextsphere.Uwp as a Cake Tool #tool nuget:?package=Apps.Contextsphere.Uwp&version=1.0.2
Overview
Contextsphere facilitates clean separation of concerns by encapsulating app's functionalities in each its own context.
This design pattern is primarily aimed at front-end development usage. Whence a developer can write code in CQRS-oriented fashion without the bulk of using message buses/hubs.
Usage
Build your app's contexts in the root node class of your choice.
public class MyRootNode : IRootNode, IHandle<MyHandledObject1>, IHandleAsync<MyHandledAsyncObject1> ...
{
...
}
In the class' constructor
public MyRootNode(IContext context, IRootNodeObject rootNodeObject, IChildNode1Object childNode1Object, IChildNode2Object childNode2Object ...)
{
// 01. core app context
var rootContext = context.CreateContext(this, ContextType.Permanent);
// 02. first child context
rootContext.CreateContext(new MyChildNode1(childNode1Object), ContextType.Permanent)
// 03. second child context (subsequent creation can be chained)
.CreateContext(new MyChildNode2(childNode2Object), ContextType.Permanent)
...
this.Context = rootContext;
}
In the consuming classes, use dependency injection to access instance of IRootNode.
private readonly IRootNode root;
...
// send calls thru the root node.
MyObject? result1 = root.Context.Handle<MyObject>();
MyObject? result2 = await root.Context.HandleAsync<MyObject>();
MyObject? result3 = root.Context.Handle<MyParam, MyObject>(myParamInstance);
MyObject? result4 = await root.Context.HandleAsync<MyParam, MyObject>(myParamInstance);
root.Context.Handle<MyObject>(myObjectInstance);
root.Context.HandleAsync<MyObject>(myObjectInstance);
// validation
bool isValid = root.Context.Validate<MyObject>(myObjectInstance);
bool isValid = await root.Context.ValidateAsync<MyObject>(myObjectInstance);
IValidationDetail<MyObject> validationDetails1 = root.Context.ValidateDetailed<MyObject>(myObjectInstance);
IValidationDetail<MyObject> validationDetails2 = await root.Context.ValidateDetailedAsync<MyObject>(myObjectInstance);
Context node classes provides the handling logic
public class MyContextNode1 : IHandleNoParamAsync<IEnumerable<MyObject>>, ...
{
public async Task<IEnumerable<MyObject>?> HandleAsync()
{
...
}
}
Concerns/Feedbacks?
You may reach me thru jakes_parane@hotmail.ph. Happy coding!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.2 | 468 | 6/25/2022 |
None