Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly registered classes are not intercepted #29

Open
cnshenj opened this issue Jun 24, 2019 · 1 comment
Open

Directly registered classes are not intercepted #29

cnshenj opened this issue Jun 24, 2019 · 1 comment

Comments

@cnshenj
Copy link

cnshenj commented Jun 24, 2019

public class Foo { public string GetName() { return nameof(Foo); } }
public class Interceptor : IInterceptor
{
    public bool Invoked { get; private set; }
    public object Invoke(IInvocationInfo invocationInfo)
    {
        this.Invoked = true;
        return invocationInfo.Proceed();
    }
}

// Directly register a class as service type and implementing type
container.Register<Foo>();
var interceptor = new Interceptor();
container.Intercept(sr => sr.ServiceType == typeof(Foo), _ => interceptor);
var foo = container.GetInstance<Foo>();
foo.GetName();

// Assertion fails
Assert.True(interceptor.Invoked);
@seesharper
Copy link
Owner

GetName has to be virtual to make that work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants