NucleusResults 1.0.0
See the version list below for details.
dotnet add package NucleusResults --version 1.0.0
NuGet\Install-Package NucleusResults -Version 1.0.0
<PackageReference Include="NucleusResults" Version="1.0.0" />
<PackageVersion Include="NucleusResults" Version="1.0.0" />
<PackageReference Include="NucleusResults" />
paket add NucleusResults --version 1.0.0
#r "nuget: NucleusResults, 1.0.0"
#:package NucleusResults@1.0.0
#addin nuget:?package=NucleusResults&version=1.0.0
#tool nuget:?package=NucleusResults&version=1.0.0
NucleusResults
Purpose
This is a very simple implementation of the known Result pattern. Its small, simple to understand, and useful for small simple applications. This pattern serves as an alternative to throwing exceptions for handling expected or non-critical errors, reducing unnecessary CPU overhead. Instead of relying on exceptions for flow control, NucleusResult<T> allows you to communicate results (data, messages, and exceptions) in a more structured and efficient way.
Key Benefits
- Improved Performance: Throwing exceptions incurs a CPU cost, particularly in high-throughput applications where exceptions can degrade performance. NucleusResult<T> avoids this by providing a lightweight way to signal success or failure.
- Enhanced Readability and Maintainability: Using NucleusResult<T> makes code flow more intuitive, as it’s clear when an operation succeeded or failed. Methods return a result directly, making it easier for developers to handle the outcome in a structured manner and avoiding null checks.
- Better User and Developer Experience: This pattern provides meaningful error messages and structured results, giving both end-users and upstream services clear feedback on what went wrong.
Usage
Success Case
public NucleusResult<Game> CreateGame()
{
var game = new Game();
return game;
}
Failure Case
public NucleusResult<Game> CreateGame()
{
try { ... }
catch(Exception ex)
{
var error = new Error(ex, "Failed to create game");
return error;
}
}
Handling Results
Direct return, can be Error or Success
public NucleusResult<SomeOtherObject> OuterMethod()
{
var result = InnerMethod();
return result;
}
When called from outer class
public NucleusResult<SomeOtherObject> OuterMethod()
{
var result = InnerMethod();
if (result.IsError)
return result.Error;
var game = result.UnWrap();
...
(Do something more)
...
}
When called from controller
public IActionResult CreateGame()
{
var result = CreateGame();
return result.Resolve(
success => Ok(result.Data),
error => BadRequest(result.Message));
}
Cases where the type T needs to change**
public NucleusResult<Alfa> DoSomething()
{
NucleusResult<Beta> result = InnerMethod();
if (result.IsError)
return result.Error;
return result.ToType<Beta, Alfa>();
}
public NucleusResult DoSomething()
{
NucleusResult<Beta> result = InnerMethod();
if (result.IsError)
return result.Error;
return result.RemoveType();
}
public NucleusResult<Alfa> DoSomething()
{
NucleusResult result = InnerMethod();
if (result.IsError)
return result.Error;
return result.AddType<Alfa>();
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNet.Mvc (>= 5.3.0)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.