|
In the example you provided you are not initializing the Order class via the container.
uc.Resolve<order>() creates an instance of the Order and then resolves its dependencies
This is why you would end up with more specialized services to initialize the objects, that are typically implemented with the container.
e.g Lets, say Order is an Entity in a domain model, you have several options about how you initialize a new one, a typical way is to have a factory, e.g IOrderFactory.Create(). Lets say for the sake of argument you are using ASP.NET and you are using dependency injection to initialize your controller paramerters via a custom controller factory (if you are unsure about that, basically a DI container is supplying dependencies to Controllers)
You would have a dependency to IOrderFactory in your controller constructor which would implement create as:
return uc.Resolve<order>();
Your order factory would be injected to your controller, and you can call orderFactory.Create() to get a new instance.
Or..
Inject the DI container into your controllers and just always call .Resolve. But I dont like to know about the DI container anywhere in my code, I prefer to have proper named services. e.g IOrderFactory is explicit, it is a Factory for creating Order objects, but by just handing a reference to your DI container everywhere you are actually hiding the dependencies. (e.g from the constructor parameters, it is not obvious what dependencies are going to be used and why)
Also - (off topic), with the example you specified above, if Order is an entity in your domain model, and you are attempting to add logging functionality to it, it is better to use a Dynamic Proxy pattern to acheive this (or) Aspect Orientated programming. It is not a dependency of the Order object to have logging functionality, it is more likely a dependency of your infrasturcture. So rather than cluttering up your order object with stuff it does not need, you can inject a Logging mechanism transparently using something like Castle Dynamic Proxy (?) You will still need to get the object from some sort of factory, but it will make your classes much cleaner.
James Simpson
Web Solutions Developer
www.methodworx.com
|
|
|
|
|
Thanks James - You know your stuff
|
|
|
|
|
Hi James - This is the solution that you provided in your last post:
"You would have a dependency to IOrderFactory in your controller constructor which would implement create as: return uc.Resolve();"
Can you please provide a constructor code block for this?
This is the closest constructor I can infer from your post:
public OrderController(IOrderFactory creator)
{
uc.Resolve();
}
1. The factory does the class creation but it's included as a param. So there is another layer of abstraction that sets the appropriate IOrderFactory? What is this additional layer of abstraction and where is it located?
2. So uc.Resolve() should be used to resolve the domain objects used by the controller? I'm assuming that the dependencies are passed down through the interface param?
I'm still trying to figure out the pieces and interaction for this.
|
|
|
|
|
I think my examples are probably more confusing than they should be. if you develop your layers without thinking about the DI layer, just rely on getting dependencies into objects via a constructor, you can add the DI container later.
Typically the container would resolve the controller (transparent to your code) and inject an instance of a factory, or repository, or service.. or whatever is needed
Then in the example of the IOrderFactory, the create could also be implemented to resolve the Order object from the same container
But, if the Order is an Entity you should be using a IOrderRepository to manipulate it, and this can include the factory method Create()
The key is to not architect your layers with the DI container in mind, just use the right sort of services to get the job done, at the end of the day they *might* be implemented using a DI container, they might not... if you working with this sort of technology your probably trying to unit test too, so if you get this right, it will probably lead you down the right path anyway.
Google sturcture map ASP.NET MVC implementation there are some good articles that demonstrate the idea behind a simple DI container and MVC.
Good luck
James
James Simpson
Web Solutions Developer
www.methodworx.com
|
|
|
|
|
While not incorrect by any means, IoC/DI can be as simple as:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Configuration;
using USCG_SSO.Interfaces;
namespace USCG_SSO
{
public class ObjectFactory<T> : IObjectFactory<T>
{
public ObjectFactory() { }
public T getInstance()
{
return getInstance(null);
}
public T getInstance(object[] initializationParameters)
{
NameValueCollection appSettings = ConfigurationManager.AppSettings;
Type type = Activator.CreateInstance(typeof(T), initializationParameters).GetType();
if (initializationParameters == null)
{
switch (type.ToString())
{
case "USCG_SSO.ServiceUser":
NameValueCollection appSettings = ConfigurationManager.AppSettings;
initializationParameters = new object[]
{
appSettings["ADUserID"],
appSettings["ADUserPassword"],
appSettings["ADFieldName"]
}
break;
case "USCG_SSO.ActiveDirectory"
initializationParameters = new object[]
{
new ObjectFactory<ServiceUser>().getInstance(),
new ObjectFactory<CurrentUser>().getInstance()
}
break;
default:
break;
}
}
return (T)Activator.CreateInstance(typeof(T), initializationParameters);
}
}
}
Assuming: USCG_SSO.ActiveDirectory object requires a ServiceUser object and a CurrentUser object to be passed in it's constructor, and USCG_SSO.ServiceUser object requires values retreived from the .config file in it's constructor. If you call
IActiveDirectory ADObject = new ObjectFactory<ActiveDirectory>().getInstance();
You would obtain an ActiveDirectory object complete with all of it's dependencies. Now, granted, this isn't as "fancy" or extensible as an actual IoC framework (there's no registration of dependencies, auto-resolution, etc.), it is, however, a complete, very simple IoC/DI implementation.
Kevin Rucker, Application Programmer
QSS Group, Inc.
United States Coast Guard OSC
Kevin.D.Rucker@uscg.mil
"Programming is an art form that fights back." -- Chad Hower
|
|
|
|
|
Hi,
I would like to know if you processed credit card payment on your ASP.NET website or one of your clients ASP.NET website..
which company you used to do it? did they have ASP.NET API?
which payment processor your recommend?
|
|
|
|
|
|
but the problem with Paypal, they don't allow international uses.. it's only for US as they told me in their email sent to me.
|
|
|
|
|
jrahma wrote: did they have ASP.NET API?
Usually no one will provide .NET specific APIs. It will be web services which can be invoked using wide variety of programming languages.
Best wishes,
Navaneeth
|
|
|
|
|
that is true.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi
I am creating a web application that will be running on an infrastructure which will utilise a number of web servers, web gardens and a load balancer.
As the application is using Sessions, and that our application is using Oracle as the database, we would like to use the database to save the Session data. However, I am struggling to find any good examples on how to do this with Oracle.
I note that Oracle provides the following class: Oracle.Web.SessionState.OracleSessionStateStore, but I am unsure what I need to do in the Code Behind and what if any tables do I need to create in the database.
Can anyone help me, please?
|
|
|
|
|
|
Hi All,
I have a windows service which is used in integration of ASP.Net web application, when I dont put any database access methods or some other external dll reference methods it executes fine, its writing in to a log file which I put to debug.
But when I put any database access methods or some other external dll reference methods or web or wcf service methods in it, its giving me following exception. Can anybody please help me in this regards. Its bit urgent please, I will also google in this meantime. Any kind of help would be appreciated.
Exception
---------------------------
Services
---------------------------
The Status Message Service service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
---------------------------
OK
---------------------------
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
indian143 wrote: Its bit urgent please
It's not professional to state urgency on a forum where people help voluntarily.
indian143 wrote: The Status Message Service service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
Is your service running on a tight loop? If not, the main thread finished execution which will exit the process. You have to do something like,
while(true)
{
} Can't you debug the code and find out why it is not working as expected? You can put Debugger.Launch on the service start up method to attach a debugger.
BTW, you are on a wrong discussion board.
Best wishes,
Navaneeth
|
|
|
|
|
Possibility #1 - There is an exception in the start event which is stopping the service.
Possibility #2 - You have not implemented a timer, hence when the start event completes its execution, service has nothing to do.
Not enough information is provided to give a concrete solution.
Found my answer helpful? Then vote for it. "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Cegonsoft malleshwaram is one of the leading Software Development Company which has three independent divisions:
i) Software Training
ii) Software Development (www.i3ITPEOPLE.com)
iii) HR Consultancy
Final Year Projects
We are providing final year projects based on System side, Web application and
IEEE projects.
System side Application in java (Swing and Applets)
Web Application in different technologies
J2EE with advanced concepts
ASP.net
PHP/MYSQL with Ajax
IEEE projects in different Transaction
IEEE in Networking
IEEE in Neural Network
IEEE in Distributed Computing
IEEE in Mobile Computing
IEEE in Software Engineering
IEEE in Image Processing
For more details contact:
hema govindaraju
9980040086
hemag@cegonsoft.net
Feel free to visit our website www.cegonsoft.com
|
|
|
|
|
These forums are for technical questions, please do not use them for advertising.
I must get a clever new signature for 2011.
|
|
|
|
|
If people are "purchasing" pre-built final year projects, no wonder there are so many absolutely useless young developers out there.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I need to allow access to particular users for some forms lying in the same folder.
I don't know how to do it using builtin ASP.NET Security setup. because new access rule is showing only folder not files (Forms.aspx).
Regrads
Asif Rehman
|
|
|
|
|
Asif Rehman wrote: because new access rule is showing only folder not files (Forms.aspx)
can you clarify the issue in more details? Are you using form authentication?If so you can allow user to access a file under secured folder specifying the role.
|
|
|
|
|
can you clarify the issue in more details? Are you using form authentication?If so you can allow user to access a file under secured folder specifying the role.
I'm using Form authentication using builtin AWT (security tool). I want to give access to different users under single folder. e.g.
Folder A
-- file1.aspx allowed to userA only
-- file2.aspx allowed to userA,B only
-- file3.aspx allowed to userC only
Now builtin tool allow folder-based authorization. I don't want to move every file to separate folder as in future authorization may change.
How can I put authorization form by form using built-in tool. If its not possible, then how to do it manually or programmatically.
Hope I've clarified my point.
Regards
Asif Rehman
|
|
|
|
|
hi,
is it possible to bind a dropdownlist in gridview when user click on the row.
i have a scenario that the gridview will load a large amount of data. then when the user
select on the dropdown, it takes 10-20 seconds to load. I was thinking that it would be better to bind the dropdownlist when the row is selected or when the dropdownlist is click on the specific row. after the user select the value of dropdownlist on the specific row, gridview automatically re-bind.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Sir, I think you should use an asynchronous callback technique (implement <a target="_blabk" href="http://msdn.microsoft.com/en-us/library/system.web.ui.icallbackeventhandler.aspx" >System.Web.UI.ICallbackEventHandler</a> )
in RowDataBound event add the following:
string args = "some thing unique";
this.DropDownList1.Attributes.Add("onclick", "javascript:DoServerCall(args);");
100
Help people,so poeple can help you.
|
|
|
|
|
Hi All,
I have a windows service, which integrates with ASP.Net application, when I am trying to install the service using following command
"installutil /account=LocalSystem /user=xxxxx /password=xxxxxatgmail StatusMessageService.exe" its giving following error. I am unable to find the reason for this any help would be appreciate.
"An exception occurred during the Install phase.
System.InvalidOperationException: Cannot open Service Control Manager on computer '.'. This operation might require other privileges.
The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: Access is denied."
My aacount credentials are correct still why is it giving this exception. Can anybody please help me in this, its little urgent. I am trying my best to do ti as well but, one shot from the other side also. Please help me, thanks.
My Service is written as below which was working before and was writing in to the file, but now when I am trying to install again its throwing exception above.
protected override void OnStart(string[] args)
{
AddToFile("Starting Service :: Time : " + DateTime.Now.ToString());
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 1000;
timer.Enabled = true;
}
protected override void OnStop()
{
timer.Enabled = false;
AddToFile("Stopping Service");
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
AddToFile(" Another entry");
}
private void AddToFile(string contents)
{
FileStream fs = new
FileStream(@"D:\Test\timerserv.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(contents);
sw.Flush();
sw.Close();
}
In the log file it is giving me the following exception
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the D:\StatusMessageService\StatusMessageService\bin\Debug\StatusMessageService.exe assembly's progress.
The file is located at D:\StatusMessageService\StatusMessageService\bin\Debug\StatusMessageService.InstallLog.
An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
The Rollback phase of the installation is beginning.
See the contents of the log file for the D:\StatusMessageService\StatusMessageService\bin\Debug\StatusMessageService.exe assembly's progress.
The file is located at D:\StatusMessageService\StatusMessageService\bin\Debug\StatusMessageService.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
modified on Thursday, February 24, 2011 6:50 PM
|
|
|
|
|
indian143 wrote: "An exception occurred during the Install phase.
System.InvalidOperationException: Cannot open Service Control Manager on computer '.'. This operation might require other privileges.
The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: Access is denied."
Looks like you need elevated privileges to perform this operation. Go to command prompt and type runas /noprofile /user:localmachinename\administrator cmd which will open up a command prompt for administrator. Try installutil from there.
Best wishes,
Navaneeth
|
|
|
|