Skip to content

Commit 4398165

Browse files
committed
ServiceContainer.GetInstance should not swallow/allow ActivationExceptions
1 parent ccd65c1 commit 4398165

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/Robo.Mvvm/ServiceContainer.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,12 @@ public static void Register(Type serviceType, Type implementationType, bool isTr
3232
}
3333

3434
public static void Register<TService>(TService instance) where TService : class
35-
{
36-
_container.RegisterInstance(instance);
37-
}
35+
=> _container.RegisterInstance(instance);
3836

39-
public static T GetInstance<T>() where T : class
40-
{
41-
try
42-
{
43-
return _container.GetInstance<T>();
44-
}
45-
catch (ActivationException)
46-
{
47-
return null;
48-
}
49-
}
37+
public static T GetInstance<T>() where T : class => _container.GetInstance<T>();
5038

5139
internal static T GetRequiredInstance<T>() where T : class
52-
{
53-
return GetInstance<T>() ?? throw new InvalidOperationException(
40+
=> GetInstance<T>() ?? throw new InvalidOperationException(
5441
$@"A required dependency injection class is missing ({typeof(T).FullName}).");
55-
}
5642
}
5743
}

0 commit comments

Comments
 (0)