Base solution for your next web application
Open Closed

Registration with multi Interface not work #8535


User avatar
0
andmattia created

Hi

I had a custom interface to register on Windsor but not work.

I add this interface to BackGroudJob

public interface IExposedJob{
...}

public class Job1Job : BackgroundJob<Job1Args>, IExposedJob, ITransientDependency
{....
}

// Manual WORK
IocManager.IocContainer.Register(
                Component.For<IExposedJob, Job1>().ImplementedBy<Job1>(),
                Component.For<IExposedJob, Job2>().ImplementedBy<Job2>()
            );
            
            // Auto not WORK
            context.IocManager.IocContainer.Register(
                Classes.FromAssembly(context.Assembly)
                    .BasedOn<IExposedJob>()
                    .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
                    .WithService.Self()
                    .WithService.Base()
                    .WithService.AllInterfaces()
            );

6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi andmattia

    You've found the solution, right?

    // Manual WORK
    IocManager.IocContainer.Register(
        Component.For<IExposedJob, Job1>().ImplementedBy<Job1>(),
        Component.For<IExposedJob, Job2>().ImplementedBy<Job2>()
    );
    

    For Windsor please check https://github.com/castleproject/Windsor/tree/master/docs

  • User Avatar
    0
    andmattia created

    No

    I found a problem but it is manual. The strange situation is that everything works except and when the class inherits from BackGround Job

  • User Avatar
    0
    aaron created
    Support Team

    What is the error?

  • User Avatar
    0
    andmattia created

    I don't have an error but if i try to search the interface it isn't registered.

  • User Avatar
    1
    aaron created
    Support Team

    I suppose it is run after RegisterAssemblyByConvention in your module.

    From https://stackoverflow.com/questions/56825208/how-to-register-concrete-class-to-generic-interface/57136227#57136227:

    For compatibility<sup>1</sup> with RegisterAssemblyByConvention, configure a unique name.

    <sup>1</sup> If your concrete class implements ASP<span></span>.NET Boilerplate's ITransientDependency, then the default name is used to register the class for .WithService.Self() inside RegisterAssemblyByConvention.

      context.IocManager.IocContainer.Register(
          Classes.FromAssembly(context.Assembly)
              .BasedOn<IExposedJob>()
              .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
              .WithService.Self()
              .WithService.Base()
              .WithService.AllInterfaces()
    +         .Configure(configurer => configurer.Named(Guid.NewGuid().ToString()))
      );
    
  • User Avatar
    0
    andmattia created

    Hi @aaron

    it works!

    Thanks a lot for your support!