<commit_before>﻿using Autofac;
using System.Management.Automation;

namespace PoshGit2.Cmdlets
{
    public class DICmdlet : Cmdlet
    {
        protected override void BeginProcessing()
        {
            base.BeginProcessing();

            PoshGit2Container.Instance.InjectUnsetProperties(this);
        }
    }
}<commit_msg>Use a lifetime scope for resolution<commit_after>﻿using Autofac;
using System;
using System.Management.Automation;

namespace PoshGit2.Cmdlets
{
    public class DICmdlet : PSCmdlet, IDisposable
    {
        private readonly ILifetimeScope _lifetimeScope;

        public DICmdlet()
        {
            _lifetimeScope = PoshGit2Container.Instance.BeginLifetimeScope(builder =>
           {
               builder.Register<SessionState>(_ => SessionState).AsSelf();
           });
        }

        protected override void BeginProcessing()
        {
            base.BeginProcessing();

            // TODO: This needs to be here for now, otherwise SessionState is not defined yet.
            // TODO: Is this called on each time something is piped through?
            _lifetimeScope.InjectUnsetProperties(this);
        }

        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _lifetimeScope.Dispose();
                }

                disposedValue = true;
            }
        }

        public void Dispose()
        {
            Dispose(true);
        }
    }
}
{'fraction_non_alphanumeric': 0.07462686567164178, 'fraction_numerical': 0.0024875621890547263, 'mean_word_length': 1.7837370242214532, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6067445', 'n_tokens_mistral': 426, 'n_tokens_neox': 405, 'n_words': 99}