Giter Site home page Giter Site logo

lefttwixwand / inventory Goto Github PK

View Code? Open in Web Editor NEW
57.0 57.0 10.0 1.19 MB

New version of Microsoft Inventory sample, built on WinUI 3, using DDD and Clean Architecture approach

License: MIT License

C# 99.20% Gherkin 0.80%
autofac chsarp clean-architecture clean-code community-toolkit cqrs ddd ddd-architecture ddd-example ddd-sample event-sourcing hacktoberfest inventory inventory-management-system mediatr project-reunion templatestudio windows-app-sdk winui winui3

inventory's People

Contributors

dependabot[bot] avatar lefttwixwand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

inventory's Issues

To improve image conversion using IValueConverter and TaskNotifier

At the current moment the image conversion works using ImageConverter class with async method to convert image from byte array to ImageSource. It's not the best coise to perform such conversion at the mapping time.

So, it would be better to implement somehow async ValueConverter and convert bytes to ImageSource on Presentation layer side.
And one of such cases I found on the Stack Overflow: https://stackoverflow.com/questions/15003827/async-implementation-of-ivalueconverter

TPH with owned types

I'm trying to store events in the Warehouses table per product id.
And all the events are inherited from WarehouseEventBase.
But now it's impossible to have TPH (Table Per Hierarchy) with owned types, like this:

internal sealed class WarehouseEntityTypeConfiguration : IEntityTypeConfiguration<Warehouse>
{
    public void Configure(EntityTypeBuilder<Warehouse> builder)
    {
        builder.ToTable("Warehouses");

        builder.HasKey(warehouse => warehouse.ProductId);

        builder.Property(warehouse => warehouse.ProductId)
            .HasColumnName(nameof(Product.Id))
            .HasConversion(id => id.Value, value => new ProductId(value));

        builder.OwnsMany(warehouse => warehouse.DomainEvents, navigationBuilder =>
        {
            navigationBuilder.UsePropertyAccessMode(PropertyAccessMode.Field);
        });
    }
}
internal sealed class WarehouseEventBaseTypeConfiguration : IEntityTypeConfiguration<WarehouseEventBase>
{
    public void Configure(EntityTypeBuilder<WarehouseEventBase> builder)
    {
        builder.HasDiscriminator<string>(nameof(WarehouseEventBase))
            .HasValue<WarehouseCreatedEvent>(nameof(WarehouseCreatedEvent))
            .HasValue<ProductsShippedEvent>(nameof(ProductsShippedEvent))
            .HasValue<ProductsMissedEvent>(nameof(ProductsMissedEvent))
            .HasValue<ProductsReceivedEvent>(nameof(ProductsReceivedEvent));
    }
}

This behavior should be implemented as soon as the feature will be added to ef core 8.
Related issue: dotnet/efcore#9630

download

Azure secured API integration

Whereas the app should have a local dB and work offline, it would be great to demonstrate how to integrate and authentic with a Azure hosted database to pull products and customers at the same time submit all orders to the api in the background without a user trigger

Domain layer

It's needed to review Microsoft Inventory Sample, and segregate the domain layer with its business logic.

The main points:

  • Clearly describe the domain layer in the Wiki
  • Create domain models
  • Unit test the domain models

Split INavigationAware into separate interfaces

Now INavigationAware interface looks like this:

public interface INavigationAware
{
    void OnNavigatedTo(object parameter);

    void OnNavigatedFrom();
}

Current implementation is not correct from the architecture point of view. It forces us to have both methods, when one of them might be surplus.

public async void OnNavigatedTo(object parameter)
{
    if (parameter is long orderId)
    {
        // Do some stuff
    }
}

public void OnNavigatedFrom()
{
    // Useless
}

Like SOLID Interface Segregation Principle says: Clients should not be forced to implement any methods they don’t use
That's why it would be better to split INavigationAware into two separate interfaces INavigatedTo and INavigatedFrom.
And as a part of code enhancement, it might be possible to make a parameter in OnNavigatedTo(object parameter) strongly typed for the cases, where we have only one possible navigation scenario.

public interface INavigatedTo<T>
{
    void OnNavigatedTo(T parameter);
}

public interface INavigatedTo : INavigatedTo<object>
{
}

public interface INavigatedFrom
{
    void OnNavigatedFrom();
}

Update ThemeSelectorService to use ThemeListener

Now the application toolbar is manually extended to match the Windows 11 style system.
But every time the theme has changed, we have to apply the toolbar style manually:
image

To avoid the code-behind, we can use the ThemeListener from the Community Toolkit to subscribe for the system theme change (if application theme is default) and handle it automatically in the separate service.

Checkbox binding

Examples of binding checkbox control to UI.
I.e Is Active field on the products table.

Improve NavigationService for automatic ObservableRecipient activation

Issue #28 describes how to use CommunityToolkit.Mvvm.Messaging for ViewModels communication. The only one problem here, is every ViewModel which listens for a message, has to be manually activated: IsActive = true; to start listening.
So, it would be good to automatically activate such ViewModels somewhere in the NavigationService.
As a bad solution - all the ObservableRecipient instances can be activated in the Autofac container callback after they've being resolved.

Integrate Pub / Sub system for view models communication

CommunityToolkit.Mvvm.Messaging provides IMessenger interface, that allows us to set up Pub / Sub system for flexible ViewModels communication.

How it can be useful?
We have a ProductsView with ProductsViewModel, which has a list of products.
And a ProductView with ProductViewModel, where we can see some detail information, modify it, delete current product or to add a new one.

After we added, edited or deleted a product - we can just send a message, what we've modified.
And the main ProductsViewModel will handle it and will update its collection.
So, we won't need to load all the products from the database after every modification - we just will need to update im-memoty Observable collection.

// Define a message
public sealed class ProductDeletedMessage : ValueChangedMessage<int>
{
    public ProductDeletedMessage(int productId) : base(productId)
    {
    }
}
// Send a message
public sealed partial class ProductViewModel : ObservableObject
{
    [RelayCommand]
    private void DeleteItem(int productId)
    {
        WeakReferenceMessenger.Default.Send(new ProductDeletedMessage(productId));
    }
}
// Handle a message
public sealed partial class ProductsViewModel : ObservableRecipient, IRecipient<ProductDeletedMessage>
{
    public ProductsViewModel()
    {
        // Activate message listener
        IsActive = true;
    }

    public ObservableCollection<ProductModel> Products { get; } = new();

    public void Receive(ProductDeletedMessagemessage)
    {
        var productToDelete = Products.First(prodcut => prodcut.Id == message.Value);
        Products.Remove(productToDelete);
    }
}

XAML Island

Create an example of using XAML Island in Win Forms app to show a "new" version of the app with new UI by integration some of the WinUI components into a WinForms app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.