|
Isn't it funny that you can't even read the software requirements for hardware being used? The hardware manufacturers mostly share the "What's in the box" guide. You can read it. Try writing something up!
If you want information about something, some technical process, some framework you can always feel free to search on CodeProject directory for articles, tip/tricks and other resources.
Requirement is that you are willing to do it, that you really want to do something.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I have read this article, An Absolute Beginner's Tutorial on Dependency Inversion Principle, Inversion of Control and Dependency Injection[^], yes it is a great article to learn this pattern and other related information. I do know how to implement it, creating an abstraction etc etc etc.
One thing that I didn't come to know what how does creating this abstraction help us out. The class is still being provided with the low-level module. So, what difference did it make when we created another interface to work around in our application. Can you please share your experience or views about Dependency Injection... Why should one use it?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: I didn't come to know what how does creating this abstraction help us out. You may want to start with writing unit tests.
Dependency on abstractions rather than concrete types results into a loosely-coupled design and more clean and "testable" code. So while unit testing, you can easily inject mock-types instead of concrete ones.
You have just been Sharapova'd.
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: The class is still being provided with the low-level module. So, what
difference did it make when we created another interface to work around in our
application You'd have to implement the interface on the class, and all that it inherits from. The advantage of the injected class is that it can be replaced easily, and that its responsibilities are limited.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Okay, so that it makes it easy to use other services in the very same class (module)... Something like that?
Because in the article, author used two services (Email, SMS) implementing the same interface (Notifier), which was injected to the high-level class for performing different action. Is that the purpose of Dependency Injection?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: Is that the purpose of Dependency Injection? I think the purpose is to separate the code that drives the behaviour of the class from the code that drives the functionality.
Another advantage that springs from your list; how hard could it be to implement another service, like "PigeonCarrierLogger"? It'd be a small, limited class; and the amount of repetitive code would stay limited.
If you're only ever going to inject a single class, then it might sounds like overkill - and it is a bit more complex to read for a novice who hasn't seen the pattern before (making things more complex).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello, i try to delete or update an entity "user" that inherite an Person abstract entity. My Person class
public abstract class Person
{
public int PersonID { get; set; }
[Required]
public string PersonCNI { get; set; }
[Required]
public string PersonName { get; set; }
public string PersonSurname { get; set; }
public int SexID { get; set; }
[ForeignKey("SexID")]
public virtual Sex Sex { get; set; }
public int AdressID { get; set; }
[ForeignKey("AdressID")]
public virtual Adress Adress { get; set; }
}
public class User : Person
{
[Required]
public string UserLogin { get; set; }
[Required]
public string UserPassword { get; set; }
public bool UserAccountState { get; set; }
public int UserAccessLevel { get; set; }
public int ProfileID { get; set; }
[ForeignKey("ProfileID")]
public virtual Profile Profile { get; set; }
public ICollection<UserBranch> UserBranches { get; set; }
}
public class EFDbContext : DbContext
{
public DbSet<Person> People { get; set; }
}
Now in one controller i have to delete an user, i have this error
"An exception of type 'System.ArgumentException' occurred in Ext.Net.dll but was not handled in user code
Additional information: Invalid data source source type. The data source must be of type IListSource, IEnumerable or IDataSource." Thank
|
|
|
|
|
Using c#,which code do I use to take a photo,save it in the phone 📱 and also be able to retrieve the same photo if I want to sent to any social media platform
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I want to build a windows forms application that is fully modular. This is an internal application for a manufacturing company.
For example: if I want to add a new screen or function, I would build an assembly. This assembly would then be discovered automatically by the application once available.
I would also like to include security for the assembly (only certain people have the right to run this screen or function).
Also I am considering using a menu or tree system in the main application to access these functions, adding items as assemblies are added for the application.
I read that MEF could be an option, but I am not familiar with it.
Can some of you give me advice on the best way to approach this?
Best wishes.
|
|
|
|
|
MEF is certainly the way I would choose to do this. You will have to put some mechanism in your UI to allow the user to select which module they wish to use, but MEF makes the discovery and loading of the module very simple. Basically, you'll be creating a catalog that you will populate with a DirectoryCatalog. This DirectoryCatalog will look for suitable types for import. There's a decent example here[^] that should help you get started.
|
|
|
|
|
I am starting to learn MEF now and it does seem like a great way to plug in functionality to an app
If I want to plugin a form and its logic, then show the form from a UI command, this would work right? (the form would really be a module of the app, accessible to those authorized)
How would this form be packaged? Make a class in a separate assembly that has all the functionality required and then have the application discover this, then just show the form from an interface function?
|
|
|
|
|
What you are proposing would work, and yes - having the form packaged in a separate assembly and loaded at runtime sounds like a fine solution.
|
|
|
|
|
Thanks for the help!
It is appreciated
Best wishes!
|
|
|
|
|
You're welcome. Glad it's inspired you.
|
|
|
|
|
|
Xaotiq wrote: var dbSets = props.Where(prop => prop.PropertyType == typeof (DbSet<>));
You can't compare the property type to a generic type definition. You'll need to check whether the property type is a generic type, and then compare its generic type definition:
var dbSets = props.Where(prop => prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>));
The easiest solution is probably to use the non-generic Set method to retrieve a non-generic DbSet from the context:
var entityTypes = typeof(YourContext)
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>))
.Select(p => p.PropertyType.GenericTypeArguments[0])
;
foreach (Type entityType in entityTypes)
{
DbSet theSet = context.Set(entityType);
theSet.RemoveRange(theSet);
}
context.SaveChanges();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I don't think there's any easy way to identify the relationships and produce a reliable order for deleting records when cascade delete is turned off.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: I don't think there's any easy way to identify the relationships and produce a reliable order for deleting records when cascade delete is turned off. Why not? I'm not sure if I'm overlooking something here (I have next to no experience with EF) but wouldn't it be "rather easily" be possible to discover the relationships by reflecting on all entity-classes, building a dependency graph from it, and then sorting it topologically to get the delete-order? (Would get nasty though with cyclic dependencies.)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The issue is with discovering the relationships between the classes. I suspect you'd need to dig in to the EDM model[^], which is rather complicated.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
It should work, providing there aren't multiple paths by which a row could be deleted. If there are, then you'll get an error from SQL:
Introducing FOREIGN KEY constraint '...' on table '...' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
You'll obviously need to update the database to enable cascade delete. Assuming you're using migrations[^], you should be able to do that without dropping the database.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
In windows form application with c#, I want to play webm file in form.
How can I do this?
Thanks.
|
|
|
|
|
Various suggestions here:
Play WebM video in Windows form[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|