This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Registramos el tipo en el contenedor | |
container.RegisterType<IRepositorioPedidos, RepositorioPedidos>(); | |
// Resolvemos usando Lazy<T> | |
var objetoLazy = container.Resolve<Lazy<IRepositorioPedidos>>(); | |
// Al usar el objeto por primera vez mediante la propiedad Value se crerá la instancia | |
var miObjeto = objetoLazy.Value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Carga diferida (activada en Entity Framework por defecto) | |
MyContext myContext = new MyContext(); | |
IList<Cliente> clientes = myContext.Clientes.ToList(); | |
IList<Pedido> pedidos = clientes.FirstOrDefault().Pedidos.ToList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Singleton | |
{ | |
private static readonly Lazy<Singleton> lazy = | |
new Lazy<Singleton>(() => new Singleton()); | |
public static Singleton Instance { get { return lazy.Value; } } | |
private Singleton() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Singleton | |
{ | |
private static Singleton instance = null; | |
private Singleton() | |
{ | |
} | |
public static Singleton Instance | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Pedidos _pedidos; | |
public Pedidos MisPedidos | |
{ | |
get | |
{ | |
if (_pedidos == null) | |
{ | |
_pedidos = new Pedidos(); | |
} | |
return _pedidos; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cliente | |
{ | |
private Lazy<Pedidos> _pedidos; | |
public Pedidos MisPedidos | |
{ | |
get | |
{ | |
return _pedidos.Value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cliente cliente = context.Clientes.Where(c => c.IdCliente == 1); | |
//... | |
// Primer acceso. Se creará la instancia | |
cliente.MisPedidos.FirstOrDefault().Enviar(); | |
// ... | |
// Siguientes accesos. Se devuelve la misma instancia | |
cliente.MisPedidos.Where(p => p.IdPedido == 150); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lazy<Pedidos> pedidos = new Lazy<Pedidos>(() => new Pedidos(idCliente)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lazy<Pedidos> pedidos = new Lazy<Pedidos>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AlineamientoAttribute : Attribute | |
{ | |
public Alineamiento Alineamiento { get; set; } | |
public AlineamientoAttribute(Alineamiento alineamiento) | |
{ | |
this.Alineamiento = alineamiento; | |
} | |
} | |