What am I missing here?
Not sure either...
South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
What am I missing here?
Again, IoC implies using interfaces in your implementations. You have DI inject concrete implementations that implement the interfaces.
During startup DI can have quite a high penalty. However as soon as that is done, each object has a reference to the concrete implementation chosen at startup time.
Not sure where the runtime cost is...
but what i am pointing out is that PRISM/Unity is SLOW in comparison to the other DI containers out there.
If you wanna use MVVM for WPF rather go with caliburn micro.
Not to mention Unity is XML configured (the last time i played with it).
Anyways enjoy deploying 50gigs of dlls with your app for the enterprise patterns.![]()
ROFL, Unity is pretty crap in my opinion.
A old but still relevant article on IoC Containers
http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison
Its hardly a millisecond, and if you start building high traffic websites with thousands of people those "milli" seconds start adding up very fast. Very narrow minded thinking imo.
public class UnityResolver
{
protected IUnityContainer container;
public UnityResolver(IUnityContainer container)
{
this.container = container ?? throw new ArgumentNullException("container");
}
public object GetService(Type serviceType)
{
try
{
return container.Resolve(serviceType);
}
catch (ResolutionFailedException)
{
return null;
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
try
{
return container.ResolveAll(serviceType);
}
catch (ResolutionFailedException)
{
return new List<object>();
}
}
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
IUnityContainer container = new UnityContainer();
container.RegisterType<IAuthorRepository, AuthorRepository>();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(container.Resolve<FrmAuthors>());
}
private IAuthorRepository _authorRepository;
public FrmAuthors(IAuthorRepository repository)
{
_authorRepository = repository;
.
.
. Peanut Butter Jelly Time
.
.
}