Coder Social home page Coder Social logo

dotnet-00-razor-blazor-azure's Introduction

dotnet-core-razor-blazor-azure

Framework & Tools

  • .NET Core 3.1
  • Visual Studio 2019
  • C#
  • Razor
  • Blazor
  • Web API
  • JSON
  • Azure

Project Structure

  • wwwroot > data > products.json (Database)
  • Components > ProductList.razor (Blazor Component)
  • Controllers > ProductsController.cs (API Controller)
  • Models > Product.cs (Object Model)
  • Services > JSONFileProductService.cs (Data Service)
public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.AddServerSideBlazor();
    services.AddControllers();
    services.AddTransient<JSONFileProductService>();
}
app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
    //endpoints.MapGet("/products", (context) =>
    //{
    //    var products = app.ApplicationServices.GetService<JSONFileProductService>().GetProducts();
    //    var json = JsonSerializer.Serialize<IEnumerable<Product>>(products);
    //    return context.Response.WriteAsync(json);
    //});
    endpoints.MapControllers();
    endpoints.MapBlazorHub();
});
  • Endpoint Route Binder for Blazor Hub which is a base class for SignalR Hub. MapBlazorHub()

Provides information about the web hosting environment an application is running in.

Great great grand parent for all iterators be it array, list, collection etc.

Provides functionality to Serialize objects or values to JSON (JavaScript Object Notation) or to Deserialize JSON to objects or values

Specifies the property name that is present in the JSON when serializing and deserializing. **[JsonPropertyName("img")]**

Reading & Deserializing JSON File data

using (var jsonFileReader = File.OpenText(JsonFileName))
{
    return JsonSerializer.Deserialize<Product[]>(jsonFileReader.ReadToEnd(),
    new JsonSerializerOptions
    {
        PropertyNameCaseInsensitive = true
    });
}

Writing & Serializing JSON File data

using (var outputStream = File.OpenWrite(JsonFileName))
{
    JsonSerializer.Serialize<IEnumerable<Product>>(
        new Utf8JsonWriter(outputStream, new JsonWriterOptions
        {
            SkipValidation = true,
            Indented = true
        }),
        products
    );
}

dotnet-00-razor-blazor-azure's People

Contributors

garymbansal avatar

Watchers

 avatar

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.