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

Update Castle.Core dependency to 4.0.0 #235

Merged
merged 6 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Castle.Facilities.Logging/LoggingFacility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ public class LoggingFacility : AbstractFacility
#if !SILVERLIGHT
private static readonly String ExtendedLog4NetLoggerFactoryTypeName =
"Castle.Services.Logging.Log4netIntegration.ExtendedLog4netFactory," +
"Castle.Services.Logging.Log4netIntegration,Version=3.3.0.0, Culture=neutral," +
"Castle.Services.Logging.Log4netIntegration,Version=4.0.0.0, Culture=neutral," +
"PublicKeyToken=407dd0808d44fbdc";

private static readonly String ExtendedNLogLoggerFactoryTypeName =
"Castle.Services.Logging.NLogIntegration.ExtendedNLogFactory," +
"Castle.Services.Logging.NLogIntegration,Version=3.3.0.0, Culture=neutral," +
"Castle.Services.Logging.NLogIntegration,Version=4.0.0.0, Culture=neutral," +
"PublicKeyToken=407dd0808d44fbdc";

private static readonly String Log4NetLoggerFactoryTypeName =
"Castle.Services.Logging.Log4netIntegration.Log4netFactory," +
"Castle.Services.Logging.Log4netIntegration,Version=3.3.0.0, Culture=neutral," +
"Castle.Services.Logging.Log4netIntegration,Version=4.0.0.0, Culture=neutral," +
"PublicKeyToken=407dd0808d44fbdc";

private static readonly String NLogLoggerFactoryTypeName =
"Castle.Services.Logging.NLogIntegration.NLogFactory," +
"Castle.Services.Logging.NLogIntegration,Version=3.3.0.0, Culture=neutral," +
"Castle.Services.Logging.NLogIntegration,Version=4.0.0.0, Culture=neutral," +
"PublicKeyToken=407dd0808d44fbdc";
#endif
private readonly string customLoggerFactoryTypeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void ApplySynchronization(ComponentModel model, IKernel kernel)
/// <param name = "model">The model.</param>
private void CheckFromAttributes(ComponentModel model)
{
var attributes = model.Implementation.GetAttributes<SynchronizeAttribute>();
var attributes = model.Implementation.GetAttributes<SynchronizeAttribute>(true);
if (attributes.Length != 0)
{
metaStore.CreateMetaFromType(model.Implementation);
Expand Down
4 changes: 2 additions & 2 deletions src/Castle.Facilities.Synchronize/SynchronizeMetaInfoStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SynchronizeMetaInfoStore(IConversionManager conversionManager)
/// <returns>The corresponding meta-info.</returns>
public SynchronizeMetaInfo CreateMetaFromType(Type implementation)
{
var syncAttrib = implementation.GetAttributes<SynchronizeAttribute>()[0];
var syncAttrib = implementation.GetAttributes<SynchronizeAttribute>(true)[0];
var metaInfo = new SynchronizeMetaInfo(syncAttrib);

PopulateMetaInfoFromType(metaInfo, implementation);
Expand Down Expand Up @@ -175,7 +175,7 @@ private static void PopulateMetaInfoFromType(SynchronizeMetaInfo metaInfo,

foreach (var method in methods)
{
var atts = method.GetAttributes<SynchronizeAttribute>();
var atts = method.GetAttributes<SynchronizeAttribute>(true);

if (atts.Length != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core-log4net" Version="3.3.0" />
<PackageReference Include="Castle.Core-log4net" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="3.3.3" />
<PackageReference Include="Castle.Core-log4net" Version="3.3.3" />
<PackageReference Include="Castle.Core" Version="4.0.0" />
<PackageReference Include="Castle.Core-log4net" Version="4.0.0" />
<PackageReference Include="NUnit" Version="3.6.1" />
<PackageReference Include="NUnit.Console" Version="3.6.1" />
</ItemGroup>
Expand All @@ -36,5 +36,5 @@
<Reference Include="System.ServiceModel.Discovery" />
<Reference Include="System.ServiceModel.Web" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ public void CanResolveClientAssociatedWithChannelUsingSuppliedModel()
}

[Test]
#if DEBUG
[Ignore("This test fails in Debug / relies on GC.Collect to clean weak reference")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat worrying that GC.Collect no longer does what it says on the tin, we've never had a problem with this in the past. Any idea what has changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, in Debug mode the JIT will choose to keep the local variable alive until the end of the method, so that it can be inspected in the debugger. This is not new, it's likely this test was failing before.

#endif
public void CanResolveClientAssociatedWithChannelUsingSuppliedEndpoint()
{
using (new WindsorContainer()
Expand Down Expand Up @@ -347,6 +350,9 @@ public void CanLazilyResolveClientAssociatedWithChannelUsingSuppliedModel()
}

[Test]
#if DEBUG
[Ignore("This test fails in Debug / relies on GC.Collect to clean weak reference")]
#endif
public void CanLazilyResolveClientAssociatedWithChannelUsingSuppliedEndpoint()
{
using (new WindsorContainer()
Expand Down
4 changes: 2 additions & 2 deletions src/Castle.Windsor.Tests/Castle.Windsor.Tests-VS2017.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Castle.Core-log4net" Version="3.3.0" />
<PackageReference Include="Castle.Core-NLog" Version="3.3.0" />
<PackageReference Include="Castle.Core-log4net" Version="4.0.0" />
<PackageReference Include="Castle.Core-NLog" Version="4.0.0" />
<PackageReference Include="NUnit" Version="3.6.1" />
<PackageReference Include="NUnit.Console" Version="3.6.1" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Castle.Windsor.Tests/ConventionVerification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private void Scan(MethodInfo interfaceMethod, MethodInfo classMethod, StringBuil
private static Tuple<TAttribute, TAttribute, bool> EnsureBothHave<TAttribute>(MethodInfo interfaceMethod, MethodInfo classMethod, StringBuilder message)
where TAttribute : Attribute
{
var fromInterface = interfaceMethod.GetAttributes<TAttribute>().SingleOrDefault();
var fromClass = classMethod.GetAttributes<TAttribute>().SingleOrDefault();
var fromInterface = interfaceMethod.GetAttributes<TAttribute>(true).SingleOrDefault();
var fromClass = classMethod.GetAttributes<TAttribute>(true).SingleOrDefault();
var bothHaveTheAttribute = true;
if (fromInterface != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Castle.Windsor/Castle.Windsor-VS2017.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="[3.3.0, 4.0.0)" />
<PackageReference Include="Castle.Core" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions src/Castle.Windsor/Core/Internal/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ private static Assembly LoadAssembly(AssemblyName assemblyName)
return Assembly.Load(assemblyName);
}
#endif
public static TAttribute[] GetAttributes<TAttribute>(this MemberInfo item) where TAttribute : Attribute

public static TAttribute[] GetAttributes<TAttribute>(this MemberInfo item, bool inherit) where TAttribute : Attribute
{
return (TAttribute[])Attribute.GetCustomAttributes(item, typeof(TAttribute), true);
return (TAttribute[])Attribute.GetCustomAttributes(item, typeof(TAttribute), inherit);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to avoid ambiguity because Castle.Core also has a GetAttributes() extension method, and it passes false for inherit

}

/// <summary>
Expand Down Expand Up @@ -307,7 +308,7 @@ private static AssemblyName GetAssemblyName(string filePath)
private static TBase Instantiate<TBase>(Type subtypeofTBase, object[] ctorArgs)
{
ctorArgs = ctorArgs ?? new object[0];
var types = ctorArgs.ConvertAll(a => a == null ? typeof(object) : a.GetType());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConvertAll() extension method from Castle.Core (CollectionExtensions.cs) no longer exists.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added EnumerableExtensions.cs

var types = ctorArgs.Select(a => a == null ? typeof(object) : a.GetType()).ToArray();
var constructor = subtypeofTBase.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, types, null);
if (constructor != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TypedFactoryConfiguration
public TypedFactoryConfiguration(string defaultComponentSelectorKey, Type factoryType)
{
this.defaultComponentSelectorKey = defaultComponentSelectorKey;
var attributes = factoryType.GetAttributes<FactoryAttribute>();
var attributes = factoryType.GetAttributes<FactoryAttribute>(true);
if (attributes.Length > 0)
{
var defaults = attributes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public void Dispose()
// that should never happen but Dispose in general is expected to be safe to call so... let's obey the rules
return;
}
localCache.Values.Reverse().ForEach(b => b.Release());
var reversed = localCache.Values.Reverse();
foreach (var burden in reversed)
{
burden.Release();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected virtual bool ReadComponentActivatorFromConfiguration(ComponentModel mo
/// <param name = "model"></param>
protected virtual void ReadComponentActivatorFromType(ComponentModel model)
{
var attributes = model.Implementation.GetAttributes<ComponentActivatorAttribute>();
var attributes = model.Implementation.GetAttributes<ComponentActivatorAttribute>(true);
if (attributes.Length != 0)
{
var attribute = attributes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public virtual void ProcessModel(IKernel kernel, ComponentModel model)
/// <param name = "implementation"></param>
protected virtual ComponentProxyBehaviorAttribute ReadProxyBehaviorFromType(Type implementation)
{
return implementation.GetAttributes<ComponentProxyBehaviorAttribute>().FirstOrDefault();
return implementation.GetAttributes<ComponentProxyBehaviorAttribute>(true).FirstOrDefault();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public virtual void ProcessModel(IKernel kernel, ComponentModel model)
protected virtual ConstructorCandidate CreateConstructorCandidate(ComponentModel model, ConstructorInfo constructor)
{
var parameters = constructor.GetParameters();
var dependencies = parameters.ConvertAll(BuildParameterDependency);
var dependencies = parameters.Select(e => BuildParameterDependency(e)).ToArray();
return new ConstructorCandidate(constructor, dependencies);
}

Expand All @@ -59,7 +59,7 @@ private static ConstructorDependencyModel BuildParameterDependency(ParameterInfo

protected virtual bool IsVisibleToContainer(ConstructorInfo constructor)
{
return constructor.HasAttribute<DoNotSelectAttribute>() == false;
return !constructor.IsDefined(typeof(DoNotSelectAttribute));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected virtual void AddInterceptor(InterceptorReference interceptorRef, Inter

protected virtual void CollectFromAttributes(ComponentModel model)
{
var attributes = model.Implementation.GetAttributes<InterceptorAttribute>();
var attributes = model.Implementation.GetAttributes<InterceptorAttribute>(true);
foreach (var attribute in attributes)
{
AddInterceptor(attribute.Interceptor, model.Interceptors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected virtual bool ReadLifestyleFromConfiguration(ComponentModel model)
/// <summary>Check if the type expose one of the lifestyle attributes defined in Castle.Model namespace.</summary>
protected virtual void ReadLifestyleFromType(ComponentModel model)
{
var attributes = model.Implementation.GetAttributes<LifestyleAttribute>();
var attributes = model.Implementation.GetAttributes<LifestyleAttribute>(true);
if (attributes.Length == 0)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private List<PropertyInfo> GetProperties(ComponentModel model, Type targetType)

private static bool HasDoNotWireAttribute(PropertyInfo property)
{
return property.HasAttribute<DoNotWireAttribute>();
return property.IsDefined(typeof(DoNotWireAttribute));
}

private static bool HasParameters(PropertyInfo property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public InterceptorGroup<TService> Interceptors(params InterceptorReference[] int
/// <returns> </returns>
public ComponentRegistration<TService> Interceptors(params Type[] interceptors)
{
var references = interceptors.ConvertAll(t => new InterceptorReference(t));
var references = interceptors.Select(t => new InterceptorReference(t)).ToArray();
return AddDescriptor(new InterceptorDescriptor(references));
}

Expand Down Expand Up @@ -633,7 +633,7 @@ public ComponentRegistration<TService> Interceptors<TInterceptor1, TInterceptor2
/// <returns> </returns>
public ComponentRegistration<TService> Interceptors(params string[] keys)
{
var interceptors = keys.ConvertAll(InterceptorReference.ForKey);
var interceptors = keys.Select(e => InterceptorReference.ForKey(e)).ToArray();
return AddDescriptor(new InterceptorDescriptor(interceptors));
}

Expand Down Expand Up @@ -813,7 +813,7 @@ public ComponentRegistration<TService> OnCreate(params Action<TService>[] action
{
return this;
}
return OnCreate(actions.ConvertAll(a => new LifecycleActionDelegate<TService>((_, o) => a(o))));
return OnCreate(actions.Select(a => new LifecycleActionDelegate<TService>((_, o) => a(o))).ToArray());
}

/// <summary>
Expand Down Expand Up @@ -848,7 +848,7 @@ public ComponentRegistration<TService> OnDestroy(params Action<TService>[] actio
{
return this;
}
return OnDestroy(actions.ConvertAll(a => new LifecycleActionDelegate<TService>((_, o) => a(o))));
return OnDestroy(actions.Select(a => new LifecycleActionDelegate<TService>((_, o) => a(o))).ToArray());
}

/// <summary>
Expand Down
6 changes: 0 additions & 6 deletions src/Castle.Windsor/SecurityAssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public partial class DefaultDiagnosticsSubSystem :

public override void Terminate()
{
diagnostics.Values.OfType<IDisposable>().ForEach(e => e.Dispose());
foreach(var element in diagnostics.Values.OfType<IDisposable>())
{
element.Dispose();
}
}

public void AddDiagnostic<TDiagnostic>(TDiagnostic diagnostic) where TDiagnostic : IDiagnostic<object>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ protected virtual void SetUpComponents(IConfiguration[] configurations, IWindsor
AssertImplementsService(component, firstService, implementation);
var defaults = CastleComponentAttribute.GetDefaultsFor(implementation);
if (defaults.ServicesSpecifiedExplicitly && services.Count == 0)
{
defaults.Services.ForEach(s => services.Add(s));
{
foreach(var service in defaults.Services)
{
services.Add(service);
}
}
name = GetName(defaults, component);
}
Expand Down