jamesmontemagno / monkey-cache

Easily cache any data structure for a specific amount of time in any .NET application.
MIT License
670 stars 106 forks source link

Problem with Barrel instance in the case of using System.Linq.Select #105

Open Senso4sLab opened 3 years ago

Senso4sLab commented 3 years ago

Here is a simplified code of my problem. The problem is that the debugger skips the last line of code which is [var _barrelResult = keys.Select(key => _barrel.Get<string>(key));]. If I use foreach loop everything works just fine. I assume that the Select method causes some problem because of an instance of _barrel. Is it possible to get some deeper explanation why this happen? It is very interesting that I do not get any exceptions. Please note this is a simplified example, in general, this code can not be applied in the constructor.

public class ViewModelGeneral: BaseViewModel
    {

        private readonly IBarrel _barrel = null;
        public ViewModelGeneral(IBarrel barrel)
        {
            _barrel = barrel;

            IList<string> keys = new List<string>();          

            // this approach works just fine
            List<string> resultsList = new List<string>();
            foreach(var key in keys)
            {
                var result = _barrel.Get<string>(key);
                resultsList.Add(result);
            }
           // this approach does not work, the debugger skips this line of code
            var _barrelResult = keys.Select(key => _barrel.Get<string>(key));

        }
    }