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

RegisterFactory with Interceptors #33

Open
ArnaudB88 opened this issue Apr 29, 2019 · 6 comments
Open

RegisterFactory with Interceptors #33

ArnaudB88 opened this issue Apr 29, 2019 · 6 comments

Comments

@ArnaudB88
Copy link

Hi,

Since the InjectionFactory is deprecated, I am trying to use the RegisterFactory method.
I have registrations which use a factory and also have interceptor(s):

Func<IUnityContainer, object> factoryFunc = c => new FileSystemWithWaitAndRetry(
	new FileSystemService(container.Resolve<System.IO.Abstractions.IFileSystem>()),
	container.Resolve<ILogger>());

container.RegisterType<IFileSystemService>(
	createLifetimeManager(),
	new InjectionFactory(factoryFunc),
	new Interceptor<InterfaceInterceptor>(),
	new InterceptionBehavior(new ImpersonationBehavior(sSettings.ImpersonatorDomain, sSettings.ImpersonatorUsername, sSettings.ImpersonatorPassword, container.Resolve<ILogger>())));

(This is a service for filesystem access with a 'wait and retry' decorator. Interception adds impersonation)

How can the RegisterType be rewritten to RegisterFactory and still pass the InterceptionBehaviour?
Is the RegisterFactory method missing some functionality?

Thanks!

@ENikS
Copy link
Contributor

ENikS commented Apr 29, 2019 via email

@ENikS ENikS transferred this issue from unitycontainer/container Jun 6, 2019
@velsietis
Copy link

@ArnaudB88
This can be done with RegisterFactory, but you need to set up the interception proxy as part of your "factoryFunc", which is a bit messy

container.RegisterFactory<IFileSystemService>(c =>
    Intercept.ThroughProxy(
        new FileSystemWithWaitAndRetry(
            new FileSystemService(container.Resolve<System.IO.Abstractions.IFileSystem>()),
            container.Resolve<ILogger>()),
        new InterfaceInterceptor(),
        new[] 
        {  new ImpersonationBehavior(
            sSettings.ImpersonatorDomain, sSettings.ImpersonatorUsername, 
            sSettings.ImpersonatorPassword, container.Resolve<ILogger>())
        }));

@ENikS
Copy link
Contributor

ENikS commented Aug 12, 2019

I am open to suggestions on how to make it more elegant.

@gdg-cardiff
Copy link

gdg-cardiff commented Aug 12, 2019

I'll try and put together a pull request on the weekend

@ENikS
Copy link
Contributor

ENikS commented Aug 13, 2019 via email

@gplutov
Copy link

gplutov commented Mar 4, 2020

Is there any about this issue?
Is there an elegant way to RegisterFactory and still pass the InterceptionBehaviour?
I'm working with unity.container, abstractions and interception 5.11.1

Is there a way to do this in 5.11.1:

unityContainer.RegisterType<TestRepository>( new InjectionFactory(container => new TestRepository()), new Interceptor<VirtualMethodInterceptor>(), new InterceptionBehavior<PolicyInjectionBehavior>());

ENikS added a commit to unitycontainer/abstractions that referenced this issue Mar 5, 2020
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

4 participants