Skip to content
This repository was archived by the owner on Apr 18, 2020. It is now read-only.

Commit 016fd22

Browse files
authored
Merge pull request #19 from osoykan/dev
proxy fix
2 parents f71fb3a + e71fff3 commit 016fd22

File tree

4 files changed

+13
-57
lines changed

4 files changed

+13
-57
lines changed

src/Autofac.Extras.IocManager.DynamicProxy/Autofac.Extras.IocManager.DynamicProxy.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>2.2.2</VersionPrefix>
4+
<VersionPrefix>2.2.3</VersionPrefix>
55
<TargetFramework>net452</TargetFramework>
66
<AssemblyName>Autofac.Extras.IocManager.DynamicProxy</AssemblyName>
77
<PackageId>Autofac.Extras.IocManager.DynamicProxy</PackageId>

src/Autofac.Extras.IocManager.DynamicProxy/AutofacInterceptionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ private static void ApplyInterception(Type[] interceptorTypes, IActivatingEventA
7979
IInterceptor[] interceptors = interceptorInstances.ToArray();
8080

8181
object interceptedInstance = interceptAdditionalInterfaces
82-
? generator.CreateClassProxyWithTarget(type, interfaces, e.Instance, interceptors)
83-
: generator.CreateClassProxyWithTarget(type, e.Instance, interceptors);
82+
? generator.CreateInterfaceProxyWithTargetInterface(theInterface, interfaces, e.Instance, interceptors)
83+
: generator.CreateInterfaceProxyWithTargetInterface(theInterface, e.Instance, interceptors);
8484

8585
e.ReplaceInstance(interceptedInstance);
8686
}

src/Autofac.Extras.IocManager/Autofac.Extras.IocManager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>2.2.2</VersionPrefix>
4+
<VersionPrefix>2.2.3</VersionPrefix>
55
<TargetFramework>net452</TargetFramework>
66
<AssemblyName>Autofac.Extras.IocManager</AssemblyName>
77
<PackageId>Autofac.Extras.IocManager</PackageId>

test/Autofac.Extras.IocManager.DynamicProxy.Tests/InterceptorRregister_Tests.cs

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
42
using System.Reflection;
53

64
using Autofac.Core;
@@ -42,9 +40,7 @@ public void interceptor_registration_with_registercallback_should_work_with_prop
4240

4341
var orderService = The<IOrderAppService>();
4442
orderService.ProductAppService.ShouldNotBeNull();
45-
46-
var orderAppService = The<OrderAppService>();
47-
orderAppService.ProductAppService.ShouldNotBeNull();
43+
orderService.DoSomeCoolStuff();
4844
}
4945

5046
[Fact]
@@ -72,20 +68,13 @@ public void multiple_interceptor_should_be_able_to_intercept_any_dependency()
7268
{
7369
Building(builder =>
7470
{
75-
builder.RegisterServices(r => r.UseBuilder(cb => cb.RegisterCallback(registry => registry.Registered += (sender, args) =>
76-
{
77-
MultipleInterceptorRegistrar(args);
78-
})));
71+
builder.RegisterServices(r => r.UseBuilder(cb => cb.RegisterCallback(registry => registry.Registered += (sender, args) => { MultipleInterceptorRegistrar(args); })));
7972
builder.RegisterServices(r => r.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()));
8073
});
8174

8275
var orderService = The<IOrderAppService>();
8376
orderService.ProductAppService.ShouldNotBeNull();
8477
orderService.DoSomeCoolStuff();
85-
86-
var orderAppService = The<OrderAppService>();
87-
orderAppService.ProductAppService.ShouldNotBeNull();
88-
orderAppService.DoSomeCoolStuff();
8978
}
9079

9180
private static void UnitOfWorkRegistrar(ComponentRegisteredEventArgs args)
@@ -149,6 +138,13 @@ public interface IOrderAppService
149138

150139
public class OrderAppService : IOrderAppService, IApplicationService
151140
{
141+
private readonly IProductAppService _productAppService;
142+
143+
public OrderAppService(IProductAppService productAppService)
144+
{
145+
_productAppService = productAppService;
146+
}
147+
152148
public IProductAppService ProductAppService { get; set; }
153149

154150
public virtual void DoSomeCoolStuff()
@@ -179,45 +175,5 @@ public void Log(string message)
179175
{
180176
}
181177
}
182-
183-
public class UnitOfWorkInterceptorRegistrarModule : Module
184-
{
185-
// This is a private constant from the Autofac.Extras.DynamicProxy2 assembly
186-
// that is needed to "poke" interceptors into registrations.
187-
private const string InterceptorsPropertyName = "Autofac.Extras.DynamicProxy2.RegistrationExtensions.InterceptorsPropertyName";
188-
189-
protected override void Load(ContainerBuilder builder)
190-
{
191-
builder.RegisterType<UnitOfWorkInterceptor>().As<IInterceptor>().AsSelf();
192-
}
193-
194-
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
195-
{
196-
// Here is where you define your "global interceptor list"
197-
var interceptorServices = new Service[] { new TypedService(typeof(UnitOfWorkInterceptor)) };
198-
199-
Type impl = registration.Activator.LimitType;
200-
201-
//Type[] services = registration.Services.OfType<TypedService>().Select(x => x.ServiceType).ToArray();
202-
203-
// Append the global interceptors to any existing list, or create a new interceptor
204-
// list if none are specified. Note this info will only be used by registrations
205-
// that are set to have interceptors enabled. It'll be ignored by others.
206-
207-
if (typeof(IApplicationService).IsAssignableFrom(impl))
208-
{
209-
object existing;
210-
if (registration.Metadata.TryGetValue(InterceptorsPropertyName, out existing))
211-
{
212-
registration.Metadata[InterceptorsPropertyName] =
213-
((IEnumerable<Service>)existing).Concat(interceptorServices).Distinct();
214-
}
215-
else
216-
{
217-
registration.Metadata.Add(InterceptorsPropertyName, interceptorServices);
218-
}
219-
}
220-
}
221-
}
222178
}
223179
}

0 commit comments

Comments
 (0)