-
-
Notifications
You must be signed in to change notification settings - Fork 126
Closed
Description
Hey. I have the following in .NET 4.8 WEB API project:
// disposable dependency
public interface ITheDependency { }
class TheDependency : ITheDependency, IDisposable
{
public void Dispose()
{
throw new NotImplementedException();
}
}
// WebApiConfig.cs.Register
var container = new Container();
container.Register<ITheDependency, TheDependency>(
Reuse.InCurrentScope // tried various scopes here
// setup: Setup.With(allowDisposableTransient: true)
);
container.WithWebApi(config);
// and dependant controller
public class ValuesController : ApiController
{
private readonly ITheDependency dependency;
private readonly IContainer container;
public ValuesController(ITheDependency dependency, IContainer container)
{
this.dependency = dependency;
this.container = container;
}
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
using (var scope = container.OpenScope())
{
var disposable = scope.Resolve<ITheDependency>();
}
return "value";
}
}New instance of TheDependency gets created and injected into ValuesController each time controller is necessary, however, once request is finished Dispose is never called on TheDependency. If scope is created and disposed manually (as in Get action with parameter) and TheDependency get resolved using that scope, Dispose is invoked.
Shouldn't disposable dependencies be disposed when web request scope is being disposed? What am I missing? DryIoc.WebApi.dll v5.0.0 is used.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels