Skip to content

Commit abbfc94

Browse files
Merge pull request MarimerLLC#1879 from dazinator/throw-when-sp-null
Throw exception when service provider is null on inject
2 parents 8fc0f04 + b47da36 commit abbfc94

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Source/Csla.Shared/Reflection/ServiceProviderMethodCaller.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,11 @@ public static async Task<object> CallMethodTryAsync(object obj, ServiceProviderM
410410
if (method.IsInjected[index])
411411
{
412412
#if !NET40 && !NET45
413-
if (service != null)
414-
plist[index] = service.GetService(item.ParameterType);
415-
//throw new InjectException(obj.GetType().Name + "." + info.Name + " " + Resources.MethodInjectFailed);
413+
if (service == null)
414+
{
415+
throw new NullReferenceException(nameof(service));
416+
}
417+
plist[index] = service.GetService(item.ParameterType);
416418

417419
#endif
418420
}

Source/csla.netcore.test/DataPortal/ServiceProviderInvocationTests.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public async Task NoServiceProvider()
4141
var obj = new TestMethods();
4242
var method = new ServiceProviderMethodInfo { MethodInfo = obj.GetType().GetMethod("Method1") };
4343
Assert.IsNotNull(method, "needed method");
44-
var result = (bool)await ServiceProviderMethodCaller.CallMethodTryAsync(obj, method, new object[] { 123 });
45-
Assert.IsTrue(result);
46-
47-
// await Assert.ThrowsExceptionAsync<InjectException>(async () => await ServiceProviderMethodCaller.CallMethodTryAsync(obj, method, new object[] { 123 }));
44+
await Assert.ThrowsExceptionAsync<NullReferenceException>(async () => await ServiceProviderMethodCaller.CallMethodTryAsync(obj, method, new object[] { 123 }));
4845
}
4946

5047
[TestMethod]

0 commit comments

Comments
 (0)