Skip to content

Commit 07e1475

Browse files
committed
Code cleanup
1 parent d09cb50 commit 07e1475

10 files changed

Lines changed: 75 additions & 74 deletions

File tree

src/UnityContainerAttributeRegistration/Adapter/AppDomainAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
namespace UnityContainerAttributeRegistration.Adapter
77
{
8-
/// <inheritdoc cref="IAppDomainAdapter"/>
8+
/// <inheritdoc cref="IAppDomainAdapter" />
99
internal class AppDomainAdapter : IAppDomainAdapter
1010
{
11-
/// <inheritdoc cref="IAppDomainAdapter.GetAssemblies"/>
11+
/// <inheritdoc cref="IAppDomainAdapter.GetAssemblies" />
1212
public IList<Assembly> GetAssemblies()
1313
{
1414
return AppDomain.CurrentDomain.GetAssemblies();

src/UnityContainerAttributeRegistration/Adapter/IAppDomainAdapter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
namespace UnityContainerAttributeRegistration.Adapter
66
{
77
/// <summary>
8-
/// Wrapper to provide <see cref="IList{Assembly}"/> instead of using <see cref="System.AppDomain"/>.
8+
/// Wrapper to provide <see cref="IList{T}" /> instead of using <see cref="System.AppDomain" />.
99
/// </summary>
1010
public interface IAppDomainAdapter
1111
{
1212
/// <summary>
13-
/// Provide <see cref="Assembly"/>s of an AppDomain.
13+
/// Provide <see cref="Assembly" />s of an AppDomain.
1414
/// </summary>
15-
/// <returns><see cref="Assembly"/>s which are used to populate.</returns>
15+
/// <returns><see cref="Assembly" />s which are used to populate.</returns>
1616
public IList<Assembly> GetAssemblies();
1717
}
1818
}

src/UnityContainerAttributeRegistration/Attribute/RegisterTypeAttribute.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
namespace UnityContainerAttributeRegistration.Attribute
77
{
88
/// <summary>
9-
/// Mark a class to be registered to an <see cref="Unity.IUnityContainer"/>
9+
/// Mark a class to be registered to an <see cref="Unity.IUnityContainer" />
1010
/// </summary>
1111
[AttributeUsage(AttributeTargets.Class)]
1212
public class RegisterTypeAttribute : System.Attribute
1313
{
1414
/// <summary>
15-
/// Candidate class for registration to <see cref="Unity"/>.
15+
/// Candidate class for registration to <see cref="Unity" />.
1616
/// </summary>
17-
/// <param name="from"><see cref="Type"/> that will be requested.</param>
18-
/// <param name="lifetimeManager">The <see cref="Unity.Lifetime.ITypeLifetimeManager"/> that controls the lifetime of the returned instance.</param>
17+
/// <param name="from"><see cref="Type" /> that will be requested.</param>
18+
/// <param name="lifetimeManager">The <see cref="Unity.Lifetime.ITypeLifetimeManager" /> that controls the lifetime of the returned instance.</param>
1919
public RegisterTypeAttribute([CanBeNull] Type from = null,
2020
[CanBeNull] Type lifetimeManager = null)
2121
{
@@ -24,14 +24,14 @@ public RegisterTypeAttribute([CanBeNull] Type from = null,
2424
}
2525

2626
/// <summary>
27-
/// <see cref="Type"/> that will be requested.
27+
/// <see cref="Type" /> that will be requested.
2828
/// </summary>
2929
[CanBeNull]
3030
internal Type From { get; }
3131

3232
/// <summary>
33-
/// The <see cref="LifetimeManager"/> that controls the lifetime
34-
/// of the returned instance.
33+
/// The <see cref="LifetimeManager" /> that controls the lifetime
34+
/// of the returned instance.
3535
/// </summary>
3636
[CanBeNull]
3737
internal Type LifetimeManager { get; }

src/UnityContainerAttributeRegistration/Exention/TypeExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
namespace UnityContainerAttributeRegistration.Exention
55
{
66
/// <summary>
7-
/// Extensions for <see cref="Type"/>.
7+
/// Extensions for <see cref="Type" />.
88
/// </summary>
99
internal static class TypeExtension
1010
{
1111
/// <summary>
12-
/// Checks if a type is static.
12+
/// Checks if a type is static.
1313
/// </summary>
14-
/// <param name="self"><see cref="Type"/> to be checked.</param>
14+
/// <param name="self"><see cref="Type" /> to be checked.</param>
1515
/// <returns>whether a type is static or not.</returns>
1616
public static bool IsStatic(this Type self)
1717
{

src/UnityContainerAttributeRegistration/Populator/IPopulator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
namespace UnityContainerAttributeRegistration.Populator
55
{
66
/// <summary>
7-
/// Interface for internal populators.
7+
/// Interface for internal populators.
88
/// </summary>
99
internal interface IPopulator
1010
{
1111
/// <summary>
12-
/// Populate the passed <paramref name="container"/>.
12+
/// Populate the passed <paramref name="container" />.
1313
/// </summary>
14-
/// <param name="container"><see cref="IUnityContainer"/> to populate.</param>
15-
/// <returns>Passed <paramref name="container"/>.</returns>
14+
/// <param name="container"><see cref="IUnityContainer" /> to populate.</param>
15+
/// <returns>Passed <paramref name="container" />.</returns>
1616
public IUnityContainer Populate(IUnityContainer container);
1717
}
1818
}

src/UnityContainerAttributeRegistration/Populator/Populator.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@
1010
namespace UnityContainerAttributeRegistration.Populator
1111
{
1212
/// <summary>
13-
/// <see cref="IPopulator"/> providing some basic functionality for reflection.
13+
/// <see cref="IPopulator" /> providing some basic functionality for reflection.
1414
/// </summary>
1515
internal abstract class Populator : IPopulator
1616
{
1717
private readonly IAppDomainAdapter appDomain;
1818

1919
/// <summary>
20-
/// ctor
20+
/// ctor
2121
/// </summary>
22-
/// <param name="appDomain">Used <see cref="IAppDomainAdapter"/> for searching for candidates.</param>
22+
/// <param name="appDomain">Used <see cref="IAppDomainAdapter" /> for searching for candidates.</param>
2323
protected Populator(IAppDomainAdapter appDomain)
2424
{
2525
this.appDomain = appDomain;
2626
}
2727

28-
/// <inheritdoc cref="IPopulator.Populate"/>
28+
/// <inheritdoc cref="IPopulator.Populate" />
2929
public abstract IUnityContainer Populate(IUnityContainer container);
3030

3131
/// <summary>
32-
/// Find all types using <typeparamref name="TAttribute"/>.
32+
/// Find all types using <typeparamref name="TAttribute" />.
3333
/// </summary>
3434
/// <param name="typeDefined">Using inheritance or not.</param>
35-
/// <typeparam name="TAttribute"><see cref="System.Attribute"/> used by searched <see cref="Type"/>s.</typeparam>
36-
/// <returns>List of all <see cref="Type"/>s in an <see cref="IAppDomainAdapter"/> using <typeparamref name="TAttribute"/>.</returns>
35+
/// <typeparam name="TAttribute"><see cref="System.Attribute" /> used by searched <see cref="Type" />s.</typeparam>
36+
/// <returns>List of all <see cref="Type" />s in an <see cref="IAppDomainAdapter" /> using <typeparamref name="TAttribute" />.</returns>
3737
protected IEnumerable<Type> GetTypesWith<TAttribute>(TypeDefined typeDefined) where TAttribute : System.Attribute
3838
{
3939
return appDomain.GetAssemblies()

src/UnityContainerAttributeRegistration/Populator/TypePopulator.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@
1616
namespace UnityContainerAttributeRegistration.Populator
1717
{
1818
/// <summary>
19-
/// Populator for the <see cref="UnityContainerAttributeRegistration.Attribute.RegisterTypeAttribute"/>.
19+
/// Populator for the <see cref="UnityContainerAttributeRegistration.Attribute.RegisterTypeAttribute" />.
2020
/// </summary>
2121
internal class TypePopulator : Populator
2222
{
2323
/// <summary>
24-
/// ctor
24+
/// ctor
2525
/// </summary>
2626
/// <param name="appDomain">
27-
/// Used <see cref="IAppDomainAdapter"/> to find all candidates using <see cref="RegisterTypeAttribute"/>
27+
/// Used <see cref="IAppDomainAdapter" /> to find all candidates using <see cref="RegisterTypeAttribute" />
2828
/// </param>
2929
public TypePopulator(IAppDomainAdapter appDomain) : base(appDomain)
3030
{
3131
}
3232

3333
/// <summary>
34-
/// Populate the passed <paramref name="container"/>.
34+
/// Populate the passed <paramref name="container" />.
3535
/// </summary>
36-
/// <param name="container"><see cref="IUnityContainer"/> to populate.</param>
37-
/// <returns>Passed <paramref name="container"/>.</returns>
36+
/// <param name="container"><see cref="IUnityContainer" /> to populate.</param>
37+
/// <returns>Passed <paramref name="container" />.</returns>
3838
/// <exception cref="InvalidOperationException">Class type must not be static or abstract.</exception>
3939
public override IUnityContainer Populate(IUnityContainer container)
4040
{
@@ -45,7 +45,8 @@ public override IUnityContainer Populate(IUnityContainer container)
4545
{
4646
if(to.IsStatic() || to.IsAbstract)
4747
{
48-
throw new InvalidOperationException($"Class type must not be static or abstract to be used with RegisterTypeAttribute: {to.FullName}");
48+
throw new InvalidOperationException(
49+
$"Class type must not be static or abstract to be used with RegisterTypeAttribute: {to.FullName}");
4950
}
5051

5152
RegisterTypeAttribute attribute = to.GetCustomAttribute<RegisterTypeAttribute>();
@@ -60,21 +61,20 @@ public override IUnityContainer Populate(IUnityContainer container)
6061
}
6162

6263
/// <summary>
63-
/// Create an instance for <paramref name="objectType"/>.
64+
/// Create an instance for <paramref name="objectType" />.
6465
/// </summary>
65-
/// <param name="objectType"><see cref="Type"/> used to create an instance.</param>
66-
/// <typeparam name="T"><paramref name="objectType"/> must be type-equal to, inherit or implement <typeparamref name="T"/>.</typeparam>
67-
/// <returns>New instance of <paramref name="objectType"/> as <typeparamref name="T"/>.</returns>
68-
/// <exception cref="InvalidOperationException">Cannot create an instance of <paramref name="objectType" />. Whether <paramref name="objectType"/> is not type-equal, does not inherit or implement <typeparamref name="T"/> or has no default constructor.</exception>
66+
/// <param name="objectType"><see cref="Type" /> used to create an instance.</param>
67+
/// <typeparam name="T"><paramref name="objectType" /> must be type-equal to, inherit or implement <typeparamref name="T" />.</typeparam>
68+
/// <returns>New instance of <paramref name="objectType" /> as <typeparamref name="T" />.</returns>
69+
/// <exception cref="InvalidOperationException">Cannot create an instance of <paramref name="objectType" />. Whether <paramref name="objectType" /> is not type-equal, does not inherit or implement <typeparamref name="T" /> or has no default constructor.</exception>
6970
[NotNull]
7071
private T GetInstanceByType<T>([NotNull] Type objectType)
7172
{
7273
Type targetType = typeof(T);
7374

7475
if(!targetType.IsAssignableFrom(objectType))
7576
{
76-
throw new InvalidOperationException(
77-
$"Type {objectType.FullName} cannot be assigned from {targetType.FullName}");
77+
throw new InvalidOperationException($"Type {objectType.FullName} cannot be assigned from {targetType.FullName}");
7878
}
7979

8080
ConstructorInfo ctor = objectType.GetConstructor(Type.EmptyTypes);

src/UnityContainerAttributeRegistration/TypeDefined.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
namespace UnityContainerAttributeRegistration
22
{
33
/// <summary>
4-
/// Enum to avoid booleans.
4+
/// Enum to avoid booleans.
55
/// </summary>
66
internal enum TypeDefined
77
{
88
/// <summary>
9-
/// Include inheritance.
9+
/// Include inheritance.
1010
/// </summary>
1111
Inherit,
12+
1213
/// <summary>
13-
/// Not include inheritance.
14+
/// Not include inheritance.
1415
/// </summary>
1516
NotInherit
1617
}

src/UnityContainerAttributeRegistration/UnityContainerPopulator.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Reflection;
5-
6-
using JetBrains.Annotations;
1+
using JetBrains.Annotations;
72

83
using Unity;
9-
using Unity.Lifetime;
104

115
using UnityContainerAttributeRegistration.Adapter;
12-
using UnityContainerAttributeRegistration.Attribute;
136
using UnityContainerAttributeRegistration.Populator;
147

158

169
namespace UnityContainerAttributeRegistration
1710
{
1811
/// <summary>
19-
/// Creates a populated or populates an <see cref="Unity.IUnityContainer" />, depending on the provided assemblies
12+
/// Creates a populated or populates an <see cref="Unity.IUnityContainer" />, depending on the provided assemblies
2013
/// </summary>
2114
public sealed class UnityContainerPopulator
2215
{
2316
private readonly IAppDomainAdapter appDomain;
24-
private readonly IPopulator TypePopulator;
17+
private readonly IPopulator TypePopulator;
2518

2619
/// <summary>
27-
/// Use <see cref="System.AppDomain.CurrentDomain"/> to populate an <see cref="Unity.IUnityContainer" />
20+
/// Use <see cref="System.AppDomain.CurrentDomain" /> to populate an <see cref="Unity.IUnityContainer" />
2821
/// </summary>
2922
public UnityContainerPopulator() : this(new AppDomainAdapter())
3023
{
3124
}
3225

3326
/// <summary>
34-
/// Use <paramref name="appDomain"/> to populate an <see cref="Unity.IUnityContainer" />
27+
/// Use <paramref name="appDomain" /> to populate an <see cref="Unity.IUnityContainer" />
3528
/// </summary>
36-
/// <param name="appDomain">Custom <see cref="UnityContainerAttributeRegistration.Adapter.IAppDomainAdapter"/></param>
29+
/// <param name="appDomain">Custom <see cref="UnityContainerAttributeRegistration.Adapter.IAppDomainAdapter" /></param>
3730
public UnityContainerPopulator([NotNull] IAppDomainAdapter appDomain)
3831
{
3932
this.appDomain = appDomain;
@@ -42,19 +35,21 @@ public UnityContainerPopulator([NotNull] IAppDomainAdapter appDomain)
4235
}
4336

4437
/// <summary>
45-
/// Create and populate a new <see cref="Unity.UnityContainer"/>
38+
/// Create and populate a new <see cref="Unity.UnityContainer" />
4639
/// </summary>
47-
/// <returns>New <see cref="Unity.UnityContainer"/> with registered types</returns>
40+
/// <returns>New <see cref="Unity.UnityContainer" /> with registered types</returns>
4841
public IUnityContainer Populate()
4942
{
5043
return Populate(new UnityContainer());
5144
}
5245

5346
/// <summary>
54-
/// Populate <paramref name="container"/>
47+
/// Populate <paramref name="container" />
5548
/// </summary>
56-
/// <param name="container"><see cref="Unity.IUnityContainer"/> to register types</param>
57-
/// <returns><paramref name="container"/></returns>
49+
/// <param name="container"><see cref="Unity.IUnityContainer" /> to register types</param>
50+
/// <returns>
51+
/// <paramref name="container" />
52+
/// </returns>
5853
public IUnityContainer Populate([NotNull] IUnityContainer container)
5954
{
6055
TypePopulator.Populate(container);

src/UnityContainerAttributeRegistrationTest/Attribute/RegisterInstanceAttributeTest.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Reflection;
5-
6-
using Moq;
74

85
using NUnit.Framework;
96

107
using Unity;
118
using Unity.Lifetime;
129

1310
using UnityContainerAttributeRegistration;
14-
using UnityContainerAttributeRegistration.Adapter;
1511

1612
using UnityContainerAttributeRegistrationTest.Assets.RegisterTypeTestClasses;
1713
using UnityContainerAttributeRegistrationTest.Helper;
@@ -25,17 +21,26 @@ internal class RegisterInstanceAttributeTest
2521
{
2622
[Test]
2723
[TestCase(typeof(Default), typeof(Default), typeof(TransientLifetimeManager))]
28-
[TestCase(typeof(ClassImplementsInterfaceWithoutLifetimeManager), typeof(IAnyInterface), typeof(TransientLifetimeManager))]
24+
[TestCase(typeof(ClassImplementsInterfaceWithoutLifetimeManager), typeof(IAnyInterface),
25+
typeof(TransientLifetimeManager))]
2926
[TestCase(typeof(ClassInheritAbstractWithoutLifetimeManager), typeof(AnyAbstractClass), typeof(TransientLifetimeManager))]
3027
[TestCase(typeof(ClassInheritClassWithoutLifetimeManager), typeof(AnyClass), typeof(TransientLifetimeManager))]
31-
[TestCase(typeof(ClassImplementsInterfaceWithHierarchicalLifetimeManager), typeof(IAnyInterface), typeof(HierarchicalLifetimeManager))]
32-
[TestCase(typeof(ClassImplementsInterfaceWithSingletonLifetimeManager), typeof(IAnyInterface), typeof(SingletonLifetimeManager))]
33-
[TestCase(typeof(ClassImplementsInterfaceWithTransientLifetimeManager), typeof(IAnyInterface), typeof(TransientLifetimeManager))]
34-
[TestCase(typeof(ClassImplementsInterfaceWithContainerControlledLifetimeManager), typeof(IAnyInterface), typeof(ContainerControlledLifetimeManager))]
35-
[TestCase(typeof(ClassImplementsInterfaceWithContainerControlledTransientManager), typeof(IAnyInterface), typeof(ContainerControlledTransientManager))]
36-
[TestCase(typeof(ClassImplementsInterfaceWithExternallyControlledLifetimeManager), typeof(IAnyInterface), typeof(ExternallyControlledLifetimeManager))]
37-
[TestCase(typeof(ClassImplementsInterfaceWithPerResolveLifetimeManager),typeof(IAnyInterface), typeof(PerResolveLifetimeManager))]
38-
[TestCase(typeof(ClassImplementsInterfaceWithPerThreadLifetimeManager),typeof(IAnyInterface), typeof(PerThreadLifetimeManager))]
28+
[TestCase(typeof(ClassImplementsInterfaceWithHierarchicalLifetimeManager), typeof(IAnyInterface),
29+
typeof(HierarchicalLifetimeManager))]
30+
[TestCase(typeof(ClassImplementsInterfaceWithSingletonLifetimeManager), typeof(IAnyInterface),
31+
typeof(SingletonLifetimeManager))]
32+
[TestCase(typeof(ClassImplementsInterfaceWithTransientLifetimeManager), typeof(IAnyInterface),
33+
typeof(TransientLifetimeManager))]
34+
[TestCase(typeof(ClassImplementsInterfaceWithContainerControlledLifetimeManager), typeof(IAnyInterface),
35+
typeof(ContainerControlledLifetimeManager))]
36+
[TestCase(typeof(ClassImplementsInterfaceWithContainerControlledTransientManager), typeof(IAnyInterface),
37+
typeof(ContainerControlledTransientManager))]
38+
[TestCase(typeof(ClassImplementsInterfaceWithExternallyControlledLifetimeManager), typeof(IAnyInterface),
39+
typeof(ExternallyControlledLifetimeManager))]
40+
[TestCase(typeof(ClassImplementsInterfaceWithPerResolveLifetimeManager), typeof(IAnyInterface),
41+
typeof(PerResolveLifetimeManager))]
42+
[TestCase(typeof(ClassImplementsInterfaceWithPerThreadLifetimeManager), typeof(IAnyInterface),
43+
typeof(PerThreadLifetimeManager))]
3944
[TestCase(typeof(ClassWithLifetimeManager), typeof(ClassWithLifetimeManager), typeof(TransientLifetimeManager))]
4045
public void TestPopulate(Type to, Type expectedFrom, Type expectedTypeLifetimeMangerType)
4146
{

0 commit comments

Comments
 (0)