{"action":"created","issue":{"url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/306","repository_url":"https://api.github.com/repos/JeremySkinner/FluentValidation","labels_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/306/labels{/name}","comments_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/306/comments","events_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/306/events","html_url":"https://github.com/JeremySkinner/FluentValidation/issues/306","id":168331204,"number":306,"title":"Cannot access a disposed object. Injection in Validator in ASP.NET Core.","user":{"login":"mdmoura","id":372865,"avatar_url":"https://avatars.githubusercontent.com/u/372865?v=3","gravatar_id":"","url":"https://api.github.com/users/mdmoura","html_url":"https://github.com/mdmoura","followers_url":"https://api.github.com/users/mdmoura/followers","following_url":"https://api.github.com/users/mdmoura/following{/other_user}","gists_url":"https://api.github.com/users/mdmoura/gists{/gist_id}","starred_url":"https://api.github.com/users/mdmoura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdmoura/subscriptions","organizations_url":"https://api.github.com/users/mdmoura/orgs","repos_url":"https://api.github.com/users/mdmoura/repos","events_url":"https://api.github.com/users/mdmoura/events{/privacy}","received_events_url":"https://api.github.com/users/mdmoura/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-29T14:00:09Z","updated_at":"2016-07-29T18:12:25Z","closed_at":null,"body":"I am using Fluent Validation with ASP.NET Core and I have the following on Startup:\r\n\r\n      services.AddDbContext<Context>(x => x.UseSqlServer(connectionString));\r\n\r\n      services.AddFluentValidation(x => x.RegisterValidatorsFromAssemblyContaining<Startup>());\r\n\r\nThen I have the following Validator:\r\n\r\n    public class TestModelValidator : AbstractValidator<TestModel> {\r\n        public TestModelValidator(Context context) {  \r\n        }\r\n    }\r\n\r\nWhen I submit the model I get the error:\r\n\r\n    ObjectDisposedException: Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur is you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.\r\n    Object name: Context\r\n    \r\nI think Validators are being registered as Singletons. Doesn't create a problem in some scenarios?\r\n\r\nWhat is the best way to solve this?\r\n\r\nThank you"},"comment":{"url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/comments/236253473","html_url":"https://github.com/JeremySkinner/FluentValidation/issues/306#issuecomment-236253473","issue_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/306","id":236253473,"user":{"login":"mdmoura","id":372865,"avatar_url":"https://avatars.githubusercontent.com/u/372865?v=3","gravatar_id":"","url":"https://api.github.com/users/mdmoura","html_url":"https://github.com/mdmoura","followers_url":"https://api.github.com/users/mdmoura/followers","following_url":"https://api.github.com/users/mdmoura/following{/other_user}","gists_url":"https://api.github.com/users/mdmoura/gists{/gist_id}","starred_url":"https://api.github.com/users/mdmoura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdmoura/subscriptions","organizations_url":"https://api.github.com/users/mdmoura/orgs","repos_url":"https://api.github.com/users/mdmoura/repos","events_url":"https://api.github.com/users/mdmoura/events{/privacy}","received_events_url":"https://api.github.com/users/mdmoura/received_events","type":"User","site_admin":false},"created_at":"2016-07-29T18:12:25Z","updated_at":"2016-07-29T18:12:25Z","body":"You mean having:\r\n\r\n    public class TestModelValidator : AbstractValidator<TestModel> {\r\n        public TestModelValidator() {  \r\n            using (Context context = new Context()) {\r\n            }\r\n        }\r\n    }\r\n\r\nIn relation to register the Validators as transient you mean (using Autofac):\r\n        x.RegisterAssemblyTypes(Assembly.GetEntryAssembly()).AsClosedTypesOf(typeof(IValidator<>)).AsImplementedInterfaces().InstancePerLifetimeScope();\r\n\r\nI suppose using the extensions:\r\n\r\n    services.AddFluentValidation(x => x.RegisterValidatorsFromAssemblyContaining<Startup>());\r\n\r\nAlways registers the validators as singletons, right?"}}
{"actor":{"display_login":"mdmoura"}}