Skip to content

Commit

Permalink
Scoped lifestyle ctors marked obsolete.
Browse files Browse the repository at this point in the history
fixes #307
  • Loading branch information
dotnetjunkie committed Nov 15, 2016
1 parent 350a757 commit 76aaada
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public class ExecutionContextScopeLifestyle : ScopedLifestyle
/// <see cref="Scope"/> instance gets disposed and when the created object implements
/// <see cref="IDisposable"/>.
/// </summary>
public ExecutionContextScopeLifestyle()
: this(disposeInstanceWhenScopeEnds: true)
public ExecutionContextScopeLifestyle() : base("Execution Context Scope")
{
}

Expand All @@ -63,17 +62,31 @@ public ExecutionContextScopeLifestyle()
/// <see cref="Scope"/> instance gets disposed and when the created object implements
/// <see cref="IDisposable"/>.
/// </param>
[Obsolete("This constructor overload has been deprecated and will be removed in a future release. " +
"Please use ExecutionContextScopeLifestyle() instead.",
error: false)]
public ExecutionContextScopeLifestyle(bool disposeInstanceWhenScopeEnds)
: this("Execution Context Scope", disposeInstanceWhenScopeEnds)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ExecutionContextScopeLifestyle"/> class.
/// </summary>
/// <param name="name">The user friendly name of this lifestyle.</param>
protected ExecutionContextScopeLifestyle(string name) : base(name)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ExecutionContextScopeLifestyle"/> class.
/// </summary>
/// <param name="name">The user friendly name of this lifestyle.</param>
/// <param name="disposeInstanceWhenScopeEnds">
/// Specifies whether the created and cached instance will be disposed when the created.</param>
[Obsolete("This constructor overload has been deprecated and will be removed in a future release. " +
"Please use ExecutionContextScopeLifestyle(string) instead.",
error: false)]
protected ExecutionContextScopeLifestyle(string name, bool disposeInstanceWhenScopeEnds)
: base(name, disposeInstanceWhenScopeEnds)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region Copyright Simple Injector Contributors
/* The Simple Injector is an easy-to-use Inversion of Control library for .NET
*
* Copyright (c) 2013-2015 Simple Injector Contributors
* Copyright (c) 2013-2016 Simple Injector Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including
Expand Down Expand Up @@ -35,8 +35,9 @@ namespace SimpleInjector.Extensions.LifetimeScoping
/// The following example shows the usage of the <b>LifetimeScopeLifestyle</b> class:
/// <code lang="cs"><![CDATA[
/// var container = new Container();
/// container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();
///
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(new LifetimeScopeLifestyle());
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(Lifestyle.Scoped);
///
/// using (container.BeginLifetimeScope())
/// {
Expand Down Expand Up @@ -65,15 +66,16 @@ namespace SimpleInjector.Extensions.LifetimeScoping
/// </example>
public sealed class LifetimeScopeLifestyle : ScopedLifestyle
{
internal static readonly LifetimeScopeLifestyle WithDisposal = new LifetimeScopeLifestyle(true);
internal static readonly LifetimeScopeLifestyle WithDisposal = new LifetimeScopeLifestyle();

#pragma warning disable 0618
internal static readonly LifetimeScopeLifestyle NoDisposal = new LifetimeScopeLifestyle(false);
#pragma warning restore 0618

/// <summary>Initializes a new instance of the <see cref="LifetimeScopeLifestyle"/> class. The instance
/// will ensure that created and cached instance will be disposed after the execution of the web
/// request ended and when the created object implements <see cref="IDisposable"/>.</summary>
public LifetimeScopeLifestyle()
: this(disposeInstanceWhenLifetimeScopeEnds: true)
public LifetimeScopeLifestyle() : base("Lifetime Scope")
{
}

Expand All @@ -83,6 +85,9 @@ public LifetimeScopeLifestyle()
/// <see cref="Scope"/> instance gets disposed and when the created object implements
/// <see cref="IDisposable"/>.
/// </param>
[Obsolete("This constructor has been deprecated and will be removed in a future release. " +
"Please use LifetimeScopeLifestyle() instead.",
error: false)]
public LifetimeScopeLifestyle(bool disposeInstanceWhenLifetimeScopeEnds)
: base("Lifetime Scope", disposeInstanceWhenLifetimeScopeEnds)
{
Expand Down
16 changes: 10 additions & 6 deletions src/SimpleInjector.Integration.Wcf/WcfOperationLifestyle.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region Copyright Simple Injector Contributors
/* The Simple Injector is an easy-to-use Inversion of Control library for .NET
*
* Copyright (c) 2013-2014 Simple Injector Contributors
* Copyright (c) 2013-2016 Simple Injector Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including
Expand Down Expand Up @@ -36,21 +36,22 @@ namespace SimpleInjector.Integration.Wcf
/// The following example shows the usage of the <b>WcfOperationLifestyle</b> class:
/// <code lang="cs"><![CDATA[
/// var container = new Container();
///
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(new WcfOperationLifestyle());
/// container.Options.DefaultScopedLifestyle = new WcfOperationLifestyle();
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(Lifestyle.Scoped);
/// ]]></code>
/// </example>
public class WcfOperationLifestyle : ScopedLifestyle
{
internal static readonly WcfOperationLifestyle WithDisposal = new WcfOperationLifestyle(true);
internal static readonly WcfOperationLifestyle WithDisposal = new WcfOperationLifestyle();

#pragma warning disable 0618
internal static readonly WcfOperationLifestyle NoDisposal = new WcfOperationLifestyle(false);
#pragma warning restore 0618

/// <summary>Initializes a new instance of the <see cref="WcfOperationLifestyle"/> class. The instance
/// will ensure that created and cached instance will be disposed after the execution of the web
/// request ended and when the created object implements <see cref="IDisposable"/>.</summary>
public WcfOperationLifestyle()
: this(disposeInstanceWhenOperationEnds: true)
public WcfOperationLifestyle() : base("WCF Operation")
{
}

Expand All @@ -59,6 +60,9 @@ public WcfOperationLifestyle()
/// Specifies whether the created and cached instance will be disposed after the execution of the WCF
/// operation ended and when the created object implements <see cref="IDisposable"/>.
/// </param>
[Obsolete("This constructor has been deprecated and will be removed in a future release. " +
"Please use WcfOperationLifestyle() instead.",
error: false)]
public WcfOperationLifestyle(bool disposeInstanceWhenOperationEnds)
: base("WCF Operation", disposeInstanceWhenOperationEnds)
{
Expand Down
11 changes: 8 additions & 3 deletions src/SimpleInjector.Integration.Web/WebRequestLifestyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,24 @@ namespace SimpleInjector.Integration.Web
/// The following example shows the usage of the <b>WebRequestLifestyle</b> class:
/// <code lang="cs"><![CDATA[
/// var container = new Container();
///
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(new WebRequestLifestyle());
/// container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(Lifestyle.Scoped);
/// ]]></code>
/// </example>
public sealed class WebRequestLifestyle : ScopedLifestyle
{
internal static readonly WebRequestLifestyle WithDisposal = new WebRequestLifestyle();

#pragma warning disable 0618
internal static readonly WebRequestLifestyle Disposeless = new WebRequestLifestyle(false);
#pragma warning restore 0618

private static readonly object ScopeCacheKey = new object();

/// <summary>Initializes a new instance of the <see cref="WebRequestLifestyle"/> class. The instance
/// will ensure that created and cached instance will be disposed after the execution of the web
/// request ended and when the created object implements <see cref="IDisposable"/>.</summary>
public WebRequestLifestyle() : this(disposeInstanceWhenWebRequestEnds: true)
public WebRequestLifestyle() : base("Web Request")
{
}

Expand All @@ -59,6 +61,9 @@ public WebRequestLifestyle() : this(disposeInstanceWhenWebRequestEnds: true)
/// Specifies whether the created and cached instance will be disposed after the execution of the web
/// request ended and when the created object implements <see cref="IDisposable"/>.
/// </param>
[Obsolete("This constructor has been deprecated and will be removed in a future release. " +
"Please use WebRequestLifestyle() instead.",
error: false)]
public WebRequestLifestyle(bool disposeInstanceWhenWebRequestEnds)
: base("Web Request", disposeInstanceWhenWebRequestEnds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ namespace SimpleInjector
/// </summary>
public static class SimpleInjectorWebApiExtensions
{
private static readonly Lifestyle LifestyleWithDisposal = new WebApiRequestLifestyle(true);
private static readonly Lifestyle LifestyleWithDisposal = new WebApiRequestLifestyle();

#pragma warning disable 0618
private static readonly Lifestyle LifestyleNoDisposal = new WebApiRequestLifestyle(false);
#pragma warning restore 0618

private static bool httpRequestMessageTrackingEnabled;

Expand Down
18 changes: 11 additions & 7 deletions src/SimpleInjector.Integration.WebApi/WebApiRequestLifestyle.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region Copyright Simple Injector Contributors
/* The Simple Injector is an easy-to-use Inversion of Control library for .NET
*
* Copyright (c) 2013 Simple Injector Contributors
* Copyright (c) 2013-2016 Simple Injector Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including
Expand All @@ -28,15 +28,15 @@ namespace SimpleInjector.Integration.WebApi
/// <summary>
/// Defines a lifestyle that caches instances during the execution of a single ASP.NET Web API Request.
/// Unless explicitly stated otherwise, instances created by this lifestyle will be disposed at the end
/// of the Web API request. Do note that this lifestyle requires the <see cref="SimpleInjectorWebApiDependencyResolver"/>
/// to be registered in the Web API configuration.
/// of the Web API request. Do note that this lifestyle requires the
/// <see cref="SimpleInjectorWebApiDependencyResolver"/> to be registered in the Web API configuration.
/// </summary>
/// <example>
/// The following example shows the usage of the <b>WebApiRequestLifestyle</b> class:
/// <code lang="cs"><![CDATA[
/// var container = new Container();
///
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(new WebApiRequestLifestyle());
/// container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
/// container.Register<IUnitOfWork, EntityFrameworkUnitOfWork>(Lifestyle.Scoped);
/// ]]></code>
/// </example>
public sealed class WebApiRequestLifestyle : ExecutionContextScopeLifestyle
Expand All @@ -45,8 +45,7 @@ public sealed class WebApiRequestLifestyle : ExecutionContextScopeLifestyle
/// The created and cached instance will be disposed when the Web API request ends, and when the
/// created object implements <see cref="IDisposable"/>.
/// </summary>
public WebApiRequestLifestyle()
: this(disposeInstanceWhenScopeEnds: true)
public WebApiRequestLifestyle() : base("Web API Request")
{
}

Expand All @@ -55,9 +54,14 @@ public WebApiRequestLifestyle()
/// Specifies whether the created and cached instance will be disposed when the Web API request ends,
/// and when the created object implements <see cref="IDisposable"/>.
/// </param>
#pragma warning disable 0618
[Obsolete("This constructor overload has been deprecated and will be removed in a future release. " +
"Please use WebApiRequestLifestyle() instead.",
error: false)]
public WebApiRequestLifestyle(bool disposeInstanceWhenScopeEnds)
: base("Web API Request", disposeInstanceWhenScopeEnds)
{
}
#pragma warning restore 0618
}
}
7 changes: 7 additions & 0 deletions src/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ Version 3.3.0 (v3.3.0 RTM)
-[Core] Improved error message in case a registration couldn't be resolved caused by incorrect
dynamic assembly loading. (fixes #325)
-[LifetimeScoping] Marked RegisterLifetimeScope and GetCurrentLifetimeScope obsolete. (fixes #303)
-[LifetimeScoping] Marked LifetimeScopeLifestyle ctor overloads that allow controlling disposal
obsolete. (fixes #307)
-[WCF] Marked RegisterPerWcfOperation and GetCurrentWcfOperationScope obsolete. (fixes #303)
-[WCF] Marked WcfOperationLifestyle ctor overloads that allow controlling disposal obsolete. (fixes #307)
-[Web] Marked RegisterPerWebRequest obsolete. (fixes #303)
-[WCF] Marked WebRequestLifestyle ctor overloads that allow controlling disposal obsolete. (fixes #307)
-[WebApi] Marked RegisterWebApiRequest obsolete. (fixes #303)
-[WebApi] Marked WebApiRequestLifestyle ctor overloads that allow controlling disposal obsolete. (fixes #307)
-[ExecutionContextScoping] Marked ExecutionContextScopingLifestyle ctor overloads that allow
controlling disposal obsolete. (fixes #307)


Version 3.2.7 (v3.2.7 RTM) 2016-11-03
Expand Down

0 comments on commit 76aaada

Please sign in to comment.