I was testing Blazor and i found out something weird, probably something i did wrong, but the result is really weird. This is not a VM, is just my laptop (Macbook pro 16GB Ram) and 1 docker container with sql server linux.
I created a new component called Buildertest with an object as a parameter. if a run the project, dotnet comsumes at least 70 GB of Ram and a lot of CPU (thats the weird part). Normally visual studio takes me to the home page in chrome almost immediatley, but not this time. the code i think is very simple:
/index.razor:
@page "/"
@using Loginnmodels2.Data
@inject IModalService Modal
<h1>Hello, world!</h1>
Welcome to your new app.
<buildertest generic_object="a" />
@code
{
private UserHasCases a = new UserHasCases();
}
Buildertest.cs:
using System;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components;
using System.Reflection;
namespace Loginnmodels2.Pages
{
public class buildertest : ComponentBase
{
[Parameter] public Loginnmodels2.Data.UserHasCases generic_object { get; set; }
private PropertyInfo[] Propiedades;
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
GetListOfProperties();
int counter = 0;
builder.OpenElement(++counter, "table");
builder.OpenElement(++counter, "tbody");
foreach (var item in Propiedades)
{
builder.OpenElement(++counter, "tr");
builder.OpenElement(++counter, "td");
builder.AddContent(++counter, item.Name);
builder.CloseElement();
builder.OpenElement(++counter, "td");
builder.OpenElement(++counter, "Input");
builder.CloseElement();
builder.CloseElement();
}
builder.CloseElement();
builder.CloseElement();
}
private void GetListOfProperties()
{
Propiedades = new PropertyInfo[5];
Propiedades = generic_object.GetType().GetProperties();
}
}
}
Of course im new into Blazor, but my guess is that somehow the parameter of the class buildertest brakes something.
any ideas? I'm using Visual Studio for Mac.
Activity Monitor screenshot
UserHasCases class:
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace Loginnmodels2.Data
{
public class UserHasCases
{
public User usr {get; set;}
public Case connected_case { get; set; }
public int Sequence { get; set; }
[Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Int64 int_counter { get; set; }
}
}
this is the class i created as service
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
//using System.Data.Entity;
using Loginnmodels2.Data;
using Microsoft.EntityFrameworkCore;
namespace Loginnmodels2.DataServices
{
public interface IUserDataService
{
Task<List<Data.User>> Get();
Task<Data.User> Get(string usr_name);
Task<Data.User> Add(Data.User a);
Task<List<Data.UserHasCases>> GetCases(User param_usr);
void Delete(Data.User a);
}
public class UserDataService : IUserDataService
{
dbcontext1 _context;
public UserDataService(dbcontext1 ctx)
{
_context = ctx;
}
public async Task<List<Data.User>> Get()
{
return await _context.Users.ToListAsync();
}
public async Task<Data.User> Get(string usr_name)
{
return await GetAllUsers().Where(x => x.user_name == usr_name).FirstOrDefaultAsync();
}
public async Task<Data.User> Add(Data.User a)
{
_context.Users.Add(a);
await _context.SaveChangesAsync();
return a;
}
public async void Delete(Data.User a)
{
_context.Users.Remove(a);
await _context.SaveChangesAsync();
}
public IQueryable<User> GetAllUsers()
{
return _context.Users.AsQueryable();
}
private IQueryable<UserHasCases> GetAllCases()
{
return _context.UserCaseRelation.AsQueryable();
}
public async Task<List<Data.UserHasCases>> GetCases(User param_usr)
{
return await GetAllCases().Where(x => x.usr == param_usr).ToListAsync();
}
public async Task<List<Data.UserHasCases>> GetAllValidCases()
{
return await GetAllCases().Where(x => x.connected_case.is_valid == true).ToListAsync();
}
}
}
this is the setup in visual studio: Setup in vstudio