Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove static logging and replacing with DI-friendly system #483

Merged
merged 11 commits into from
Feb 2, 2023

Conversation

andyward
Copy link
Member

@andyward andyward commented Feb 1, 2023

…DI approach for #455

Attempted as much as possible to break few contracts, and provide forwarding to new implementation

Removed dependence on Microsoft.Extensions.Logging, but added Microsoft.Extensions.DependencyInjection

Works by introducing an internal DI ServiceCollection and ServiceProvider available via a singleton resource. This collection can be configured by a consumer, but services will work out the box without any config (just with Null Logging)

Consumers can add own logging, either with AddLogging(), or by telling xbim to UseLoggerFactory(logFactory).

Removed public Setter ILoggers. Because we're not fully in control of DI composition favoured approach is to inject/pass in ILoggerFactory to key roots. We're using ServiceLocator anti-pattern in other cases as a last resort.

ModelProvider & Factory has been re-worked to actually work with DI.

One subtle change - Previosuly Heuristic ModelProvider kicked in if Esent was loaded. Now that needs to be set explicitly when configuring the app.

i.e. XbimServices.Current.ConfigureServices(s => s.AddXbimToolkit(opt => opt.UseHeuristicModel()));

Legacy 'DI lite' concepts like IfcStore.ModelProviderFactory.UseHeuristicModelProvider() have been remapped to a new approach and Obsoleted.

TODO: many tests use the old obsoleted overloads, which forward onto new . All tests pass (with one flaky IfcStore ModelProvider test to resolve)

…DI approach for #455

Attempted as much as possible to break few contracts, and provide forwarding to new implementation

Removed dependence on Microsoft.Extensions.Logging, but added Microsoft.Extensions.DependencyInjection

Works by introducing an internal DI ServiceCollection and ServiceProvider available via a singleton resource. This collection can be configured by a consumer, but services will work out the box without any config (just with Null Logging)

Consumers can add own logging, either with AddLogging(), or by telliing xbim to UseLoggerFactory(logFactory).

Removed public Setter ILoggers. Because we're not fully in control of DI composition favoured approach is to inject/pass in ILoggerFactory to key roots. We're using ServiceLocator anti-pattern in other cases as a last resort.

ModelProvider & Factory has been re-worked to actually work with DI.

One subtle change - Previosuly Heuristic ModelProvider kicked in if Esent was loaded. Now that needs to be set explicitly when configuring the app.

i.e. XbimServices.Current.ConfigureServices(s => s.AddXbimToolkit(opt => opt.UseHeuristicModel()));

Legacy 'DI lite' concepts like IfcStore.ModelProviderFactory.UseHeuristicModelProvider() have been remapped to a new approach and Obsoleted.

TODO: many tests use the old obsoleted overloads, which forward onto new .
All tests pass (with one flaky IfcStore ModelProvider test to resolve)
Directory.Build.props Outdated Show resolved Hide resolved
Copy link
Member Author

@andyward andyward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial notes and comments

Tests/DefaultModelProviderFactoryTests.cs Outdated Show resolved Hide resolved
Tests/DependencyInjectionTests.cs Outdated Show resolved Hide resolved
Xbim.Common/Xbim.Common.csproj Show resolved Hide resolved
Xbim.IO.Esent/ModelProviderExtensions.cs Show resolved Hide resolved
Xbim.IO.MemoryModel/DefaultModelProviderFactory.cs Outdated Show resolved Hide resolved
Xbim.Ifc/IfcStore.cs Outdated Show resolved Hide resolved
Xbim.Ifc/IfcStore.cs Outdated Show resolved Hide resolved
Xbim.Ifc/IfcStore.cs Show resolved Hide resolved
Xbim.Common/Configuration/XbimServices.cs Show resolved Hide resolved
Caused by random sequencing of tests and shared state
Fixed up defaults on obsolete methods so typical upgraders will auto pick up new implementations by default. i.e. will default to ILoggerFactory signature over ILogger when caller didn't provide any logger
Addresses all test warnings except Scanner
…oryModel.

Added some guards/logging to Esent & Heurisrstic ModelProvider infrastructure when used under non WIndows o/s
Replaced by ServiceLocator

None-breaking as these were only added lately after obsoleting the equivalent ILogger param methods and related DI work
We're mix & match xUnit and vsTest... xUnit classes need Bootstrapping reliably or sequencing issues can trigger failures in singleton state
@andyward andyward changed the title WIP: First pass at removing static logging and replacing with a more … Remove static logging and replacing with DI system Feb 2, 2023
@andyward andyward changed the title Remove static logging and replacing with DI system Remove static logging and replacing with DI-friendly system Feb 2, 2023
@andyward andyward merged commit 91015d6 into develop Feb 2, 2023
@andyward andyward deleted the feature/LoggingInjection-455 branch February 2, 2023 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant