Git Product home page Git Product logo

blazor.eventaggregator's People

Contributors

dradovic avatar mikoskinen 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  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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blazor.eventaggregator's Issues

Not working as expected, cause too much render on the component which suscribe

Hi @mikoskinen and thanks for your work !

However i see a huge problem in your library.
Indeed i faced a performance issue with my app, and i see some of my components are definitively render too much (dotnet/aspnetcore#14684)
i debug this and i see each time one of the event aggregator (whatever the parameters) publish, all of the components wich suscribe (whatever the parameters) are re-loaded (i see them with put some trace on the ShouldRender when the value is true, when i traced back the call stach i arrive on the publish of components).

I precise i see this behavior is client-side (web assembly)

so if you have a component C1 wich publish the a message of type T1 and and component C2 which suscribe of message of type T2, C2 is reloaded when C1 publish, which make no sense, normally the type is used to isolate the different case.

In my case, the components was reloaded 8 time instead of 1. I don't take time to debug your code so i don't know what is causing this issue. However, i see you try to called automatically the StateAsChanged in your code, i think it's a bad idea, In my case sometime i don't want to relad my components (some are very huge) and can be a performance problem event without this bug. at least provide an option to disable it (or better, as a parameter of the publish).

Maybe i can make some PR if you need help.

Good luck

Julien

Blazor WASM net6.0

Just a note for anyone else...

I experienced a few issues using this package on a Blazor WASM net6.0 solution.

In the end I found that https://www.nuget.org/packages/Caliburn.Micro.Core/ is current and contains an updated version of the EventAggregator which is working fine in my solution (Blazor.EventAggregator is based on an older version of Caliburn).

builder.Services.AddScoped<Caliburn.Micro.IEventAggregator, Caliburn.Micro.EventAggregator>();

_eventAggregator.SubscribeOnPublishedThread(this);

await _eventAggregator.PublishOnCurrentThreadAsync(new MyMessage())

Unsubscribe?

Does the subscriber have to call Unsubscribe in order to prevent memory leaks (as the EventAggregator is registered as a singleton)?

Server side Blazor shares state with AddSingleton<IEventAggregator, EventAggregator.Blazor.EventAggregator>();

I would suggest you add an enum called ImplementationType having the following:

public enum ImplementationType { Singleton, Scoped, Transient }

And add a property to the ServiceCollectionExtensions:

public ImplementationType ImplementationType { get; set; }

Which means you now can tell the AddEventAggregator method which way to dependency inject the IEventAggregator:

`
public static IServiceCollection AddSpecialEventAggregator(this IServiceCollection services, Action configure = null)
{
if (configure != null)
{
SpecialEventAggregatorOptions options = new SpecialEventAggregatorOptions();
configure(options);

    if (options.ImplementationType == ImplementationType.Transient)
    {
        services.AddTransient<IEventAggregator, EventAggregator.Blazor.EventAggregator>();
    }
    else if (options.ImplementationType == ImplementationType.Scoped)
    {
        services.AddScoped<IEventAggregator, EventAggregator.Blazor.EventAggregator>();
    }
    else
    {
        services.AddSingleton<IEventAggregator, EventAggregator.Blazor.EventAggregator>();
    }

    services.Configure(configure);
}
else
{
    services.AddSingleton<IEventAggregator, EventAggregator.Blazor.EventAggregator>();
}

return services;

}`

EventAggregator.Blazor 1.1.0, blazor preview 8: IL linker fails during compilation

Symptom

2>Fatal error in IL Linker
2>
2>Unhandled Exception: Mono.Linker.MarkException: Error processing method: 'System.Threading.Tasks.Task Microsoft.AspNetCore.Components.Browser.RendererRegistryEventDispatcher::DispatchEvent(Microsoft.AspNetCore.Components.Browser.RendererRegistryEventDispatcher/BrowserEventDescriptor,System.String)' in assembly: 'Microsoft.AspNetCore.Components.Browser.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Threading.Tasks.Task Microsoft.AspNetCore.Components.Rendering.Renderer::DispatchEventAsync(System.Int32,Microsoft.AspNetCore.Components.UIEventArgs)
2> at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
2> at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
2> at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
2> at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
2> at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
2> at Mono.Linker.Steps.MarkStep.ProcessQueue()
2> --- End of inner exception stack trace ---
2> at Mono.Linker.Steps.MarkStep.ProcessQueue()
2> at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
2> at Mono.Linker.Steps.MarkStep.Process()
2> at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
2> at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
2> at Mono.Linker.Pipeline.Process(LinkContext context)
2> at Mono.Linker.Driver.Run(ILogger customLogger)
2> at Mono.Linker.Driver.Execute(String[] args, ILogger customLogger)
2> at Mono.Linker.Driver.Main(String[] args)

Reprosteps

Just add (reference) NuGet package EventAggregator.Blazor 1.1.0 to project and build the project.

Enviroment

.NET Core 3.0.100-preview8-013656
Microsoft.AspNetCore.Blazor 3.0.0-preview8

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.