-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Address issue #578 by providing an internal service provider we fall …
…back on when no services have been configured (either explicitly via XbimServices.ConfigureServices, or implicitly in static initialisers in IfcStore, GeometryEngine etc). Updated Readme
- Loading branch information
Showing
5 changed files
with
133 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Xbim.Common.Configuration | ||
{ | ||
/// <summary> | ||
/// An Internal Service provider which serves as a fall back to a minimal services implementation when the consuming application | ||
/// does not yet explicitly registered the xbim services or <see cref="IServiceProvider"/> on <see cref="XbimServices"/>. | ||
/// The fallback services provides a safe baseline but provides no Logging capability. | ||
/// XBIM INTERNAL USE ONLY. Prefer <see cref="XbimServices"/> | ||
/// </summary> | ||
internal class InternalServiceProvider | ||
{ | ||
/// <summary> | ||
/// Gets the internal ServiceProvider | ||
/// </summary> | ||
public IServiceProvider ServiceProvider { get; } | ||
|
||
private readonly static Lazy<InternalServiceProvider> lazySingleton; | ||
|
||
static InternalServiceProvider() | ||
{ | ||
lazySingleton = new Lazy<InternalServiceProvider>(() => new InternalServiceProvider()); | ||
} | ||
|
||
private InternalServiceProvider() | ||
{ | ||
// Set up minimal services required to use Geometry. | ||
var services = new ServiceCollection(); | ||
// Provide a NullLogger implementation so DI dependencies are satsisfied. We don't have a concrete Logger implementation we can use | ||
services.AddSingleton<ILoggerFactory, NullLoggerFactory>(); | ||
services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(NullLogger<>))); | ||
|
||
//services.AddXbimToolkit(opt => opt); | ||
ServiceProvider = services.BuildServiceProvider(); | ||
|
||
var warning = @$"NOTE: The xbim InternalServices are being used because Xbim.Common.Configuration.XbimServices has not yet been configured. This fallback service provider has no logging support so you may miss useful output from xbim. To see xbim logs ensure you provide a LoggerFactory to {typeof(XbimServices).FullName} at startup - or provide an existing ServiceProvider to the XbimServices. e.g. | ||
XbimServices.Current.ConfigureServices(s => s.AddXbimToolkit(c => c.AddLoggerFactory(loggerFactory))); | ||
// or | ||
XbimServices.Current.UseExternalServiceProvider(serviceProvider);"; | ||
|
||
Debug.WriteLine(warning); | ||
Console.Error.WriteLine(warning); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Current instance of the <see cref="InternalServiceProvider"/> | ||
/// </summary> | ||
public static InternalServiceProvider Current { get => lazySingleton.Value; } | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters