-
Notifications
You must be signed in to change notification settings - Fork 458
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
Burdens are not Release Policy aware from TypedFactories for disposables #373
Closed
Closed
Changes from all commits
Commits
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
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
93 changes: 93 additions & 0 deletions
93
src/Castle.Windsor.Tests/TypedFactoryDisposableTestCase.cs
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,93 @@ | ||
// Copyright 2004-2011 Castle Project - http://www.castleproject.org/ | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace CastleTests | ||
{ | ||
using System; | ||
|
||
using Castle.MicroKernel; | ||
using Castle.MicroKernel.Registration; | ||
using Castle.MicroKernel.SubSystems.Configuration; | ||
using Castle.Windsor; | ||
|
||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class TypedFactoryDisposableTestCase : AbstractContainerTestCase | ||
{ | ||
private ServiceInstaller serviceInstaller; | ||
|
||
protected override void AfterContainerCreated() | ||
{ | ||
serviceInstaller = new ServiceInstaller(); | ||
Container.Install(serviceInstaller); | ||
} | ||
|
||
[Test] | ||
public void Can_resolve_service_using_factory_that_implements_disposable() | ||
{ | ||
var a = Container.Resolve<IDatabaseConnectionExecutor>(); | ||
Assert.That(a, Is.Not.Null); | ||
} | ||
|
||
public class ServiceInstaller : IWindsorInstaller | ||
{ | ||
public void Install(IWindsorContainer container, IConfigurationStore store) | ||
{ | ||
container.Register( | ||
Component.For<ISomeConnectionService>() | ||
.ImplementedBy<SomeConnectionService>() | ||
.LifestyleTransient()); | ||
|
||
container.Register( | ||
Component.For<FailoverDatabaseConnectionExecutor>() | ||
.LifestyleTransient()); | ||
|
||
container.Register(Component.For<IDatabaseConnectionExecutor>() | ||
.UsingFactoryMethod<IDatabaseConnectionExecutor>((k) => k.Resolve<FailoverDatabaseConnectionExecutor>()) | ||
.LifestyleTransient() | ||
.IsDefault()); | ||
} | ||
|
||
} | ||
|
||
public interface ISomeConnectionService | ||
{ | ||
} | ||
|
||
public class SomeConnectionService : ISomeConnectionService, IDisposable | ||
{ | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
|
||
public interface IDatabaseConnectionExecutor | ||
{ | ||
} | ||
|
||
public class FailoverDatabaseConnectionExecutor : IDatabaseConnectionExecutor | ||
{ | ||
private readonly ISomeConnectionService _someConnectionService; | ||
|
||
public FailoverDatabaseConnectionExecutor(ISomeConnectionService someConnectionService) | ||
{ | ||
this.InstanceId = Guid.NewGuid(); | ||
_someConnectionService = someConnectionService; | ||
} | ||
|
||
public Guid InstanceId { get; set; } | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,13 +25,15 @@ namespace Castle.MicroKernel | |
public class Burden | ||
{ | ||
private readonly IHandler handler; | ||
private readonly IReleasePolicy releasePolicy; | ||
private Decommission decommission = Decommission.No; | ||
|
||
private List<Burden> dependencies; | ||
|
||
internal Burden(IHandler handler, bool requiresDecommission, bool trackedExternally) | ||
internal Burden(IHandler handler, IReleasePolicy releasePolicy, bool requiresDecommission, bool trackedExternally) | ||
{ | ||
this.handler = handler; | ||
this.releasePolicy = releasePolicy; | ||
TrackedExternally = trackedExternally; | ||
if (requiresDecommission) | ||
{ | ||
|
@@ -89,7 +91,32 @@ public bool RequiresDecommission | |
/// </summary> | ||
public bool RequiresPolicyRelease | ||
{ | ||
get { return TrackedExternally == false && RequiresDecommission; } | ||
get | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need a new abstraction. |
||
{ | ||
var isAlreadyTracked = releasePolicy.HasTrack(Instance); | ||
var isLateBound = Model.Implementation == typeof(LateBoundComponent); | ||
|
||
// If we track externally, we want to bail out early | ||
if (TrackedExternally) | ||
{ | ||
return false; | ||
} | ||
|
||
// If we are not tracked extenerally but we are not late bound go ahead with default resolve | ||
if (!isLateBound && !TrackedExternally) | ||
{ | ||
return RequiresDecommission; | ||
} | ||
|
||
// We are not tracked externally, but we are late bound, if we have disposables we are burden N+1 tracked via TypedFactory and non TypeFactory component registrations for any given component type <T> | ||
if (isLateBound && !TrackedExternally) | ||
{ | ||
return RequiresDecommission && !isAlreadyTracked; | ||
} | ||
|
||
// Fallback logic for non type factory types T | ||
return !TrackedExternally && RequiresDecommission; | ||
} | ||
} | ||
|
||
public bool TrackedExternally { get; set; } | ||
|
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
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.
Why?