Skip to content

Commit

Permalink
chore: Removed references to Castle.Windsor and enabled AutoFac conta…
Browse files Browse the repository at this point in the history
…iner in net462 builds as well as netstandard2.0
  • Loading branch information
tippmar-nr committed Jul 19, 2023
1 parent 974335c commit 2389469
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 127 deletions.
12 changes: 5 additions & 7 deletions src/Agent/NewRelic/Agent/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.5.0" />
<PackageReference Include="Google.Protobuf" Version="3.21.12" />
<PackageReference Include="Grpc.Tools" Version="2.28.1">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -58,16 +59,15 @@
<!-- .NET Framework needs to use the legacy gRPC library -->
<PackageReference Include="Grpc" Version="2.46.6" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
<PackageReference Include="Castle.Core" Version="3.3.0" />
<PackageReference Include="Castle.Windsor" Version="3.3.0" />
<!--<PackageReference Include="Castle.Core" Version="3.3.0" />
<PackageReference Include="Castle.Windsor" Version="3.3.0" />-->
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="Serilog.Sinks.EventLog" Version="3.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<!-- .NET Core can use the modern gRPC library -->
<PackageReference Include="Grpc.Net.Client" Version="2.55.0" />
<PackageReference Include="Autofac" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
Expand Down Expand Up @@ -99,12 +99,11 @@
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'NewRelic.Parsing'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Google.Protobuf'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Grpc.Core.Api'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Autofac'" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Grpc.Core'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Castle.Core'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Castle.Windsor'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'ICSharpCode.SharpZipLib'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Newtonsoft.Json'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog'" />
Expand All @@ -126,7 +125,6 @@
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Microsoft.Extensions.Logging.Abstractions'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Grpc.Net.Common'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Grpc.Net.Client'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Autofac'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Newtonsoft.Json'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog'" />
<ILRepackInclude Include="@(PossibleRefsForILRepack)" Condition="'%(FileName)' == 'Serilog.Expressions'" />
Expand All @@ -138,7 +136,7 @@
</ItemGroup>

<PropertyGroup>
<ILRepackIncludeCount Condition="'$(TargetFramework)' == 'net462'">21</ILRepackIncludeCount>
<ILRepackIncludeCount Condition="'$(TargetFramework)' == 'net462'">20</ILRepackIncludeCount>
<ILRepackIncludeCount Condition="'$(TargetFramework)' == 'netstandard2.0'">16</ILRepackIncludeCount>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public static class AgentServices
{
public static IContainer GetContainer()
{
#if NETFRAMEWORK
return new WindsorContainer();
#else
return new CoreContainer();
#endif
}

/// <summary>
Expand Down Expand Up @@ -136,9 +132,6 @@ public static void RegisterServices(IContainer container)
container.Register<IApiSupportabilityMetricCounters, IOutOfBandMetricSource, ApiSupportabilityMetricCounters>();
container.Register<ICATSupportabilityMetricCounters, IOutOfBandMetricSource, CATSupportabilityMetricCounters>();
container.Register<IAgentTimerService, AgentTimerService>();
#if NETFRAMEWORK
container.RegisterFactory<IEnumerable<IOutOfBandMetricSource>>(container.ResolveAll<IOutOfBandMetricSource>);
#endif
container.Register<IThreadPoolStatic, ThreadPoolStatic>();
container.Register<ITransactionTransformer, TransactionTransformer>();
container.Register<ICustomEventTransformer, CustomEventTransformer>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

#if NETSTANDARD2_0
using System;
using System.Collections.Generic;
using Autofac;
Expand Down Expand Up @@ -84,13 +83,11 @@ public void ReplaceInstanceRegistration<TInterface>(TInterface instance)

public T Resolve<T>()
{
Check(typeof(T));
return _scope.Resolve<T>();
}

public IEnumerable<T> ResolveAll<T>()
{
Check(typeof(T));
try
{
return _scope.Resolve<IEnumerable<T>>();
Expand All @@ -101,13 +98,7 @@ public IEnumerable<T> ResolveAll<T>()
throw;
}
}
private void Check(Type type)
{
if (_scope == null)
{
throw new Exception("Resolve invoked with uninitialized container for " + type);
}
}


protected virtual void Dispose(bool disposing)
{
Expand All @@ -134,4 +125,3 @@ public void Dispose()
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ void ReplaceInstanceRegistration<TInterface>(TInterface instance)

void Build();

#if NETSTANDARD
void ReplaceRegistrations();
#endif
}
}

This file was deleted.

3 changes: 0 additions & 3 deletions tests/Agent/UnitTests/CompositeTests/CompositeTestAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ public CompositeTestAgent(bool shouldAllowThreads, bool includeAsyncLocalStorage
}

_container.ReplaceInstanceRegistration(configurationManagerStatic);

#if NET
_container.ReplaceRegistrations(); // creates a new scope, registering the replacement instances from all .ReplaceRegistration() calls above
#endif

InstrumentationService = _container.Resolve<IInstrumentationService>();
InstrumentationWatcher = _container.Resolve<InstrumentationWatcher>();
Expand Down
6 changes: 1 addition & 5 deletions tests/Agent/UnitTests/CompositeTests/CompositeTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JustMock" Version="2020.1.113.1" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="MoreLinq" Version="2.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand All @@ -21,11 +22,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Castle.Core" Version="3.3.0" />
<PackageReference Include="Castle.Windsor" Version="3.3.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="1.1.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
</ItemGroup>
Expand Down

0 comments on commit 2389469

Please sign in to comment.