-
Notifications
You must be signed in to change notification settings - Fork 934
WIP - Replace IObjectsFactory with IServiceProvider interface #1793
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
Open
maca88
wants to merge
16
commits into
nhibernate:master
Choose a base branch
from
maca88:IServiceProvider
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4aca182
Replace IObjectsFactory with IServiceProvider interface
maca88 98485e0
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte 4f5cae4
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte ae4d2b4
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte c52ec3b
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte d72268f
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte 131830b
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte 79b5c5a
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte e61274a
fixup! Replace IObjectsFactory with IServiceProvider interface
fredericDelaporte 2b2950c
Removed registration logic from DefaultServiceProvider and renamed it…
maca88 b256937
Added a fallback mechanism for internal types when the IoC container …
maca88 8cc22f8
Added the fallback also for external types
maca88 b31157a
Renamed GetInstance to GetMandatoryService
maca88 cf3bbf6
Fixed GetService usages
maca88 357b628
Regenerate async
maca88 d52629b
Upgrade async generator to 0.8.2.10
maca88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/NHibernate.Test/Async/CfgTest/SettingsFactoryFixture.cs
This file contains hidden or 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,82 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using System.Collections.Generic; | ||
using NHibernate.AdoNet; | ||
using NHibernate.Bytecode; | ||
using NHibernate.Cache; | ||
using NHibernate.Cfg; | ||
using NHibernate.Connection; | ||
using NHibernate.Exceptions; | ||
using NHibernate.Hql; | ||
using NHibernate.Hql.Ast.ANTLR; | ||
using NHibernate.Linq.Functions; | ||
using NHibernate.Linq.Visitors; | ||
using NHibernate.Transaction; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using Environment = NHibernate.Cfg.Environment; | ||
|
||
namespace NHibernate.Test.CfgTest | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class SettingsFactoryFixtureAsync | ||
{ | ||
|
||
[Test] | ||
public async Task InvalidRegisteredServicesAsync() | ||
{ | ||
await (InvalidRegisteredServiceAsync<IBatcherFactory>()); | ||
await (InvalidRegisteredServiceAsync<ICacheProvider>()); | ||
await (InvalidRegisteredServiceAsync<IConnectionProvider>()); | ||
await (InvalidRegisteredServiceAsync<Dialect.Dialect>()); | ||
await (InvalidRegisteredServiceAsync<ILinqToHqlGeneratorsRegistry>()); | ||
await (InvalidRegisteredServiceAsync<IQueryCacheFactory>()); | ||
await (InvalidRegisteredServiceAsync<IQueryModelRewriterFactory>()); | ||
await (InvalidRegisteredServiceAsync<IQueryTranslatorFactory>()); | ||
await (InvalidRegisteredServiceAsync<ITransactionFactory>()); | ||
} | ||
|
||
private Task InvalidRegisteredServiceAsync<TService>() | ||
{ | ||
try | ||
{ | ||
var originalSp = Environment.ServiceProvider; | ||
|
||
var sp = new DefaultServiceProvider(); | ||
sp.Register<TService>(() => throw new InvalidOperationException()); | ||
|
||
Environment.ServiceProvider = sp; | ||
|
||
var properties = new Dictionary<string, string> | ||
{ | ||
{Environment.UseQueryCache, "true"} | ||
}; | ||
if (typeof(TService) != typeof(Dialect.Dialect)) | ||
{ | ||
properties.Add(Environment.Dialect, typeof(Dialect.PostgreSQL83Dialect).FullName); | ||
} | ||
|
||
Assert.Throws<HibernateException>( | ||
() => new SettingsFactory().BuildSettings(properties), | ||
$"HibernateException should be thrown for service {typeof(TService)}"); | ||
|
||
Environment.ServiceProvider = originalSp; | ||
return Task.CompletedTask; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<object>(ex); | ||
} | ||
} | ||
} | ||
} |
79 changes: 0 additions & 79 deletions
79
src/NHibernate.Test/Bytecode/ActivatorObjectFactoryFixture.cs
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/NHibernate.Test/Bytecode/DefaultServiceProviderFixture.cs
This file contains hidden or 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,75 @@ | ||
using System; | ||
using NHibernate.Bytecode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Bytecode | ||
{ | ||
[TestFixture] | ||
public class DefaultServiceProviderFixture | ||
{ | ||
public class WithOutPublicParameterLessCtor | ||
{ | ||
public string Something { get; set; } | ||
protected WithOutPublicParameterLessCtor() { } | ||
|
||
public WithOutPublicParameterLessCtor(string something) | ||
{ | ||
Something = something; | ||
} | ||
} | ||
|
||
public class PublicParameterLessCtor | ||
{ | ||
} | ||
|
||
protected virtual IServiceProvider GetServiceProvider() | ||
{ | ||
return new DefaultServiceProvider(); | ||
} | ||
|
||
[Test] | ||
public void CreateInstanceDefCtor() | ||
{ | ||
var sp = GetServiceProvider(); | ||
Assert.Throws<ArgumentNullException>(() => sp.GetService(null)); | ||
Assert.Throws<MissingMethodException>(() => sp.GetService(typeof(WithOutPublicParameterLessCtor))); | ||
var instance = sp.GetService(typeof(PublicParameterLessCtor)); | ||
Assert.That(instance, Is.Not.Null); | ||
Assert.That(instance, Is.InstanceOf<PublicParameterLessCtor>()); | ||
} | ||
|
||
|
||
[Test] | ||
public void RegisterService() | ||
{ | ||
var sp = new DefaultServiceProvider(); | ||
|
||
Assert.That(sp.GetService(typeof(IInterceptor)), Is.Null); | ||
|
||
sp.Register<IInterceptor, EmptyInterceptor>(); | ||
var instance = sp.GetService(typeof(IInterceptor)); | ||
Assert.That(instance, Is.Not.Null); | ||
Assert.That(instance, Is.InstanceOf<EmptyInterceptor>()); | ||
|
||
Assert.Throws<InvalidOperationException>(() => sp.Register<IInterceptor, EmptyInterceptor>(), "service should not be registered twice."); | ||
Assert.Throws<InvalidOperationException>(() => sp.Register<Dialect.Dialect, Dialect.Dialect>(), "non concrete implementation type should not be permitted."); | ||
Assert.Throws<InvalidOperationException>(() => sp.Register(typeof(Dialect.Dialect), typeof(EmptyInterceptor)), "concrete implementation type should derive from service type."); | ||
} | ||
|
||
[Test] | ||
public void RegisterServiceCreator() | ||
{ | ||
var sp = new DefaultServiceProvider(); | ||
|
||
Assert.That(sp.GetService(typeof(IInterceptor)), Is.Null); | ||
|
||
sp.Register<IInterceptor>(() => new EmptyInterceptor()); | ||
var instance = sp.GetService(typeof(IInterceptor)); | ||
Assert.That(instance, Is.Not.Null); | ||
Assert.That(instance, Is.InstanceOf<EmptyInterceptor>()); | ||
|
||
Assert.Throws<InvalidOperationException>(() => sp.Register<IInterceptor>(() => new EmptyInterceptor()), "service should not be registered twice."); | ||
} | ||
|
||
} | ||
} |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NHibernate.Bytecode; | ||
using NUnit.Framework; | ||
using Environment = NHibernate.Cfg.Environment; | ||
|
||
namespace NHibernate.Test.CfgTest | ||
{ | ||
[TestFixture] | ||
public class CustomServiceProviderTest | ||
{ | ||
private class MyServiceProvider : IServiceProvider | ||
{ | ||
public object GetService(System.Type serviceType) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
private class InvalidServiceProvider | ||
{ | ||
} | ||
private class InvalidNoCtorServiceProvider : MyServiceProvider | ||
{ | ||
public InvalidNoCtorServiceProvider(string pizza) {} | ||
} | ||
|
||
[Test] | ||
public void WhenNoShortCutUsedThenCanBuildServiceProvider() | ||
{ | ||
var properties = new Dictionary<string, string> { { Environment.PropertyBytecodeProvider, typeof(MyServiceProvider).AssemblyQualifiedName } }; | ||
Assert.That(() => Environment.BuildServiceProvider(properties), Throws.Nothing); | ||
} | ||
|
||
[Test] | ||
public void WhenNoShortCutUsedThenCanBuildInstanceOfConfiguredServiceProvider() | ||
{ | ||
var properties = new Dictionary<string, string> { { Environment.PropertyServiceProvider, typeof(MyServiceProvider).AssemblyQualifiedName } }; | ||
Assert.That(Environment.BuildServiceProvider(properties), Is.InstanceOf<MyServiceProvider>()); | ||
} | ||
|
||
[Test] | ||
public void WhenInvalidThenThrow() | ||
{ | ||
var properties = new Dictionary<string, string> { { Environment.PropertyServiceProvider, typeof(InvalidServiceProvider).AssemblyQualifiedName } }; | ||
Assert.That(() => Environment.BuildServiceProvider(properties), Throws.TypeOf<HibernateServiceProviderException>()); | ||
} | ||
|
||
[Test] | ||
public void WhenNoDefaultCtorThenThrow() | ||
{ | ||
var properties = new Dictionary<string, string> { { Environment.PropertyServiceProvider, typeof(InvalidNoCtorServiceProvider).AssemblyQualifiedName } }; | ||
Assert.That(() => Environment.BuildServiceProvider(properties), Throws.TypeOf<HibernateServiceProviderException>() | ||
.And.InnerException.Message.Contains("constructor was not found")); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should not be generated as there is nothing async, it is a bug related to async generator that I need to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I released a new version of the async generator (
0.8.2.10
) that fixes the issue of generating non async methods.