Skip to content

πŸŽ‰ SnapshotIt. Before changing the state of component, just snapshot the state, to make it easy to recovery.

Notifications You must be signed in to change notification settings

AkhmedovEhson/SnapshotIt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SnapshotIt

πŸŽ‰ Snapshot It 1.0.0. Before changing the state of component, just snapshot the state of object to make it easy to recovery.

image

Requirements

  • .NET 8

Documentation

πŸ’š Snapshot It is extensionable lightweight-library, provides bunch of extensions.

  • πŸ“ Snapshotting - simply snapshot any instance in any context of application, and use it in runtime of application.
  • πŸ—ƒοΈ Copying - copy any instance.
  • 🌐 Channel `BufferBlock` - use it as unbounded channel, post, read, close.

πŸ–ŠοΈ We have a class Product (?)

public class Product
{
    public int Id {get;set}
    public string Name{get;set;}
}

// Copy class
var product = new Product() { Id = 1,Name = "Product" } // note, it is reference type and mutable
var product2 = Snapshot.Out.Copy(product); // copies `product`

🐹 Let's do following steps....

using SnapshotIt;

var product = new Product() 
{
    Id = 1
    Name = "Nike"
}
Snapshot.Out.Create<Product>(10); // initialized collection of `Product` with size `10`
Snapshot.Out.Post<Product>(product); // captures state

product.Id = 2;
product.Name = "Gucci";

const int index = 0;
// Gets the first snapshot from capture collection
// By default index = 0, using index easily can find the correct captured instance
var Capturedproduct = Snapshot.Out.Get<Product>(index);
// or use expressions
var Capturedproduct = Snapshot.Out.Get<Product>(o => o.Id == n);


// Logs: The product's name is Gucci
log.Information($"The product's name is {product.Name}");

// Logs: The previous product's name was Nike 
log.Information($"The previous product's name was {Capturedproduct.Name}");

πŸ’š ASP.NET and Dependency Injections

using SnapshotIt.DependencyInjection;

// Actually for injecting stuff into class, you are injecting from $constructor
public class UserController : BaseController
{
    public ILogger logger;
    public UserController(ILogger logger) 
    {
        this.logger = logger;
    }
}

// You can communicate with DI container very easy </>
// Use following steps ...
public class UserController : BaseController
{
    public ILogger logger = Connector.GetService<ILogger>(); // you got it :)
}

✨🎨 Registration of services to dependency injection container.

using SnapshotIt.DependencyInjection;

// Interface should be named same as class but with prefix `I` [!]
[RuntimeDependencyInjectionOption(Lifetime = ServiceLifetime.Scoped)]
public class ProductRepository : IProductRepository{}

[RuntimeDependencyInjectionOption(Lifetime = ServiceLifetime.Transient)]
public class ColorRepository : IColorRepository{}

var RuntimeServicesRegisterExecutor = new RuntimeRegisterServices(Assembly.GetExecutingAssembly(), services);

RuntimeServicesRegisterExecutor.ConfigureAllServices(); 

About

πŸŽ‰ SnapshotIt. Before changing the state of component, just snapshot the state, to make it easy to recovery.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages