Skip to content

Commit

Permalink
Merge pull request #696 from dolittle/tenant-specific-exception
Browse files Browse the repository at this point in the history
Throw a friendlier exception when failing to resolve tenant specific …
  • Loading branch information
woksin committed Jun 1, 2022
2 parents 6c8d2b9 + c12977a commit 4ddf0c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Dolittle.Runtime.Domain.Tenancy;

namespace Dolittle.Runtime.DependencyInversion.Tenancy;

/// <summary>
/// Exception that gets thrown when autofac fails to resolve a tenant specific service.
/// </summary>
public class FailedToResolveServiceForTenant : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="FailedToResolveServiceForTenant"/> class.
/// </summary>
/// <param name="tenant">The tenant id it fails to resolve service for.</param>
/// <param name="service">The service it fails to resolve.</param>
/// <param name="resolutionException">The inner autofac resolution exception.</param>
public FailedToResolveServiceForTenant(TenantId tenant, Type service, Exception resolutionException)
: base($"Failed to resolve tenant specific service {service} for tenant {tenant}", resolutionException)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Fun
{
var provider = providers.ForTenant(tenant);
var resolver = provider.GetRequiredService(tenantDelegateToResolve) as Delegate;
return resolver?.DynamicInvoke(arguments); //TODO: Null check?
try
{
return resolver?.DynamicInvoke(arguments); //TODO: Null check?
}
catch (Exception e)
{
throw new FailedToResolveServiceForTenant(tenant, resolvedType, e);
}
};

var generatedDelegateParameters = parameters.Select(_ => Expression.Parameter(_.ParameterType, _.Name)).ToList();
Expand Down

0 comments on commit 4ddf0c4

Please sign in to comment.