Petite Question sur le lazy loading
Bonjour,
j 'ai une petite Question sur le lazy loading. Il y a un comportement de l'application que je ne comprends pas. J'utilise asp.net 3.5 et visual studio 2008.
Voila j'ai le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| private IList<ProjectProvider> _Projects;
private ICatalogRepository _CatalogRepository;
public IList<ProjectProvider> Projects
{
get
{
if (_Projects == null && _CatalogRepository!=null)
{
_Projects = new LazyList<ProjectProvider>();
LoadProjects();
}
return _Projects;
}
set
{
_Projects = value;
}
}
public void LoadProjects()
{
if (_CatalogRepository != null)
_Projects = _CatalogRepository.GetProjects().ToList();
else
throw new Exception("No Catalog Repository found.");
}
public void SetRepository(ICatalogRepository userrepository)
{
_CatalogRepository = userrepository;
} |
Code:
1 2
| MonObjet _MonObjet = new MonObjet();
MonObjet.SetRepository(RepositoryCatalog); |
Lorsque je cree mon objet la liste de mes projets est bien null. Tant la variable privee que la variable publique mais dés que je met quelque chose dans _catalogrepository, ma variable projet se trouve instanciée sans que je lui ai dit quoi que ce soit.
Est ce normal Docteur?