Skip to content

Type Activator For Decorator, Does Not Invoke Dependency's Factory if It Has Conditions #279

@falamarzijahromi

Description

@falamarzijahromi

I'm trying to use the decorator feature with ctor param by using Castle Dynamic Proxy for generating dynamic proxy types as decorators for using them as interceptors. When I Export the dependency by factory under any conditions , it doesn't work. But there's no problem if the dependency does not have any conditions.

` block
.ExportDecorator(decoratorType)
.As(tServiceType)
.WithCtorParam<GenericCastleInterceptor, IInterceptor[]>(i => new IInterceptor[] { i });

      block
            .ExportFactory<IServiceProvider, GenericCastleInterceptor>(sp =>
            {
                return new GenericCastleInterceptor(applicationInterceptorsTypes, sp);
            })
            .As<GenericCastleInterceptor>()
            .When.InjectedInto(type =>
            {
                return true;
            })
            .When.MeetsCondition((strategy, context) =>
            {
                return true;
            });

`

or

` block
.ExportDecorator(decoratorType)
.As(tServiceType)
.WithCtorParam<GenericCastleInterceptor, IInterceptor[]>(i => new IInterceptor[] { i });

      block
            .ExportFactory<IServiceProvider, GenericCastleInterceptor>(sp =>
            {
                return new GenericCastleInterceptor(applicationInterceptorsTypes, sp);
            })
            .As<GenericCastleInterceptor>()
            .When.InjectedInto(decoratorType);

`

The above code snippets do not work whether using InjectedInto or hacking with MeetsCondition to make conditions for exporting. But the code snippet below works well.

` block
.ExportDecorator(decoratorType)
.As(tServiceType)
.WithCtorParam<GenericCastleInterceptor, IInterceptor[]>(i => new IInterceptor[] { i });

      block
            .ExportFactory<IServiceProvider, GenericCastleInterceptor>(sp =>
            {
                return new GenericCastleInterceptor(applicationInterceptorsTypes, sp);
            })
            .As<GenericCastleInterceptor>();

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions